Merge branch 'master' of https://github.com/LucasGGamerM/moshidon into moshidon-iceshrimp-improvements
4
.github/FUNDING.yml
vendored
|
@ -1,11 +1,11 @@
|
||||||
# These are supported funding model platforms
|
# These are supported funding model platforms
|
||||||
|
|
||||||
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
github: LucasGGamerM
|
||||||
patreon: # mastodon
|
patreon: # mastodon
|
||||||
open_collective: # Replace with a single Open Collective username e.g., user1
|
open_collective: # Replace with a single Open Collective username e.g., user1
|
||||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||||
liberapay: # Replace with a single Liberapay username e.g., user1
|
liberapay: LucasGGamerM # Replace with a single Liberapay username e.g., user1
|
||||||
issuehunt: # Replace with a single IssueHunt username e.g., user1
|
issuehunt: # Replace with a single IssueHunt username e.g., user1
|
||||||
otechie: # Replace with a single Otechie username e.g., user1
|
otechie: # Replace with a single Otechie username e.g., user1
|
||||||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||||
|
|
6
.github/ISSUE_TEMPLATE/bug_report.md
vendored
|
@ -22,12 +22,10 @@ Steps to reproduce the behavior:
|
||||||
**Does this happen in the official app?**
|
**Does this happen in the official app?**
|
||||||
|
|
||||||
Does this issue also occur with the respective upstream release?
|
Does this issue also occur with the respective upstream release?
|
||||||
(Please test using the respective `upstream-xxxxxx.apk` provided in [Releases](https://github.com/sk22/megalodon/releases) or at least using the current Mastodon version from the Play Store)
|
|
||||||
|
|
||||||
> No / Yes
|
> No / Yes
|
||||||
|
|
||||||
> In case it does, please consider filing an [upstream bug report](https://github.com/mastodon/mastodon-android/issues) instead.
|
> In case it does, please consider filing an [upstream bug report](https://github.com/mastodon/mastodon-android/issues) instead.
|
||||||
> If this bug is seriously impacting your usage or you think I might want to try to fix it for Megalodon, feel free to still create this issue!
|
> If this bug is seriously impacting your usage or you think I might want to try to fix it for Moshidon, feel free to still create this issue!
|
||||||
|
|
||||||
**Screenshots and screen recordings**
|
**Screenshots and screen recordings**
|
||||||
|
|
||||||
|
@ -35,7 +33,7 @@ If applicable, add screenshots (and screen recordings, if possible) to help expl
|
||||||
|
|
||||||
**Version**
|
**Version**
|
||||||
|
|
||||||
Megalodon version: [e.g. v1.1.4+fork.#]
|
Moshidon version: [e.g. v1.1.4+fork.#]
|
||||||
|
|
||||||
**Crash log**
|
**Crash log**
|
||||||
|
|
||||||
|
|
71
.github/workflows/nightly-builds.yml
vendored
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
name: Nightly builds
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ "master" ]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
# - name: Checkout Appkit Repo
|
||||||
|
# uses: actions/checkout@v3
|
||||||
|
# with:
|
||||||
|
# repository: grishka/appkit
|
||||||
|
#
|
||||||
|
# - name: set up JDK 17
|
||||||
|
# uses: actions/setup-java@v3
|
||||||
|
# with:
|
||||||
|
# java-version: '17'
|
||||||
|
# distribution: 'corretto'
|
||||||
|
# cache: gradle
|
||||||
|
#
|
||||||
|
# - name: Comment out signing config in appkits gradle file
|
||||||
|
# run: |
|
||||||
|
# sed -i 's/sign publishing\.publications\.release/\/\/ sign publishing.publications.release/' appkit/maven-push.gradle
|
||||||
|
#
|
||||||
|
# - name: Grant execute permission for gradlew for Appkit
|
||||||
|
# run: chmod +x gradlew
|
||||||
|
#
|
||||||
|
# - name: Compile appkit
|
||||||
|
# run: ./gradlew publishToMavenLocal
|
||||||
|
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: set up JDK 17
|
||||||
|
uses: actions/setup-java@v3
|
||||||
|
with:
|
||||||
|
java-version: '17'
|
||||||
|
distribution: 'corretto'
|
||||||
|
cache: gradle
|
||||||
|
|
||||||
|
- name: Get current date
|
||||||
|
id: date
|
||||||
|
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Grant execute permission for gradlew
|
||||||
|
run: chmod +x gradlew
|
||||||
|
|
||||||
|
- name: Decode Keystore
|
||||||
|
id: decode_keystore
|
||||||
|
uses: timheuer/base64-to-file@v1
|
||||||
|
with:
|
||||||
|
fileName: 'nightly_keystore.jks'
|
||||||
|
fileDir: './mastodon/keystore/'
|
||||||
|
encodedString: ${{ secrets.KEYSTORE }}
|
||||||
|
|
||||||
|
- name: Build with Gradle
|
||||||
|
run: ./gradlew assembleNightly
|
||||||
|
env:
|
||||||
|
SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }}
|
||||||
|
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
|
||||||
|
SIGNING_STORE_PASSWORD: ${{ secrets.SIGNING_STORE_PASSWORD }}
|
||||||
|
CURRENT_DATE: ${{ steps.date.outputs.date }}
|
||||||
|
|
||||||
|
- name: Upload a Build Artifact
|
||||||
|
uses: actions/upload-artifact@v3.1.2
|
||||||
|
with:
|
||||||
|
name: moshidon-nightly.apk
|
||||||
|
path: ./mastodon/build/outputs/apk/nightly/moshidon-nightly.apk
|
2
.gitignore
vendored
|
@ -9,3 +9,5 @@
|
||||||
.cxx
|
.cxx
|
||||||
local.properties
|
local.properties
|
||||||
*.jks
|
*.jks
|
||||||
|
*.keystore
|
||||||
|
/mastodon/keystore/nightly_keystore.keystore
|
||||||
|
|
9
FAQ.md
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
## F.A.Q
|
||||||
|
|
||||||
|
Q: What are the main differences between Moshidon and Megalodon?
|
||||||
|
|
||||||
|
A: There are many, but the most outstanding differences are: the ability to have other server's local timeline inside the app. It can be acessed in the "Add community" option in the top right corner of the Edit timelines screen. Other outstanding features that Moshidon has are some quality of life improvements, such as notification actions and allowing for unlisted replies by default. Most other features are pretty minor, such as profile notes directly available in the person's profile. Other features are quite minor usability and visibility improvements. All of which can be found in the settings page.
|
||||||
|
|
||||||
|
Q: Will there ever be a version of Moshidon for iOS?
|
||||||
|
|
||||||
|
A: No. As android and iOS apps do not share code, it is incredibly hard to port.
|
231
README.md
|
@ -1,128 +1,125 @@
|
||||||

|

|
||||||
|
|
||||||
# Megalodon
|
# Moshidon, the material you mastodon client!
|
||||||
|
|
||||||
[](https://translate.codeberg.org/engage/megalodon/)
|
> A fork of [megalodon](https://github.com/sk22/megalodon) which is a fork of [official Mastodon Android app](https://github.com/mastodon/mastodon-android) adding important features that are missing in the official app and possibly won’t ever be implemented, such as the federated timeline, unlisted posting, bookmarks and an image description viewer.
|
||||||
|
|
||||||
|
|
||||||
|
[](https://github.com/LucasGGamerM/moshidon/releases/latest/download/moshidon.apk)
|
||||||
|
|
||||||
|
[](https://github.com/LucasGGamerM/moshidon-nightly/releases/latest/download/moshidon-nightly.apk)
|
||||||
|
|
||||||
|
|
||||||
|
[](https://translate.codeberg.org/engage/moshidon/)
|
||||||
|
|
||||||
[](https://github.com/sk22/megalodon/releases/latest/download/megalodon.apk)
|
[](https://github.com/LucasGGamerM/moshidon/actions/workflows/nightly-builds.yml)
|
||||||
|
|
||||||
<a href="https://play.google.com/store/apps/details?id=org.joinmastodon.android.sk"><img height="50" alt="Get it on Google Play" src="img/google-play-badge.png"></a>
|
<a href="https://play.google.com/store/apps/details?id=org.joinmastodon.android.moshinda"><img height="50" alt="Get it on Google Play" src="img/google-play-badge.png"></a>
|
||||||
|
|
||||||
<a href="#installation"><img height="50" alt="Get it on IzzyOnDroid" src="img/izzy-badge.png"></a>
|
<a href="https://f-droid.org/pt_BR/packages/org.joinmastodon.android.moshinda"><img height="50" alt="Get it on F-Droid" src="img/f-droid-badge.png"></a>
|
||||||
|
|
||||||
|
<a href="https://apt.izzysoft.de/fdroid/index/apk/org.joinmastodon.android.moshinda"><img height="50" alt="Get it on IzzyOnDroid" src="img/izzy-badge.png"></a>
|
||||||
|
|
||||||
> A fork of the [Mastodon Android app](https://github.com/mastodon/mastodon-android) adding important features that are missing in the official app, focusing on [Glitch](https://glitch-soc.github.io/docs) compatibility, a pretty UI and adding new features that I feel make using the Fediverse a more pleasant experience.
|
## Help out the project by donating at: https://github.com/sponsors/LucasGGamerM!
|
||||||
|
### We also support LiberaPay at: https://liberapay.com/LucasGGamerM/donate
|
||||||
|
|
||||||
|
### You can also donate some Monero through this wallet address as well:
|
||||||
|
4886mdarcyB6Yf8Qc6vDJBK1fz6ibHFLZUmHb4GZZz9yLGNhcG3XC64e5UZ8dVQYTLZb82W6P9WhteowW4STJEec97Gf22j
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Key features
|
## Key features
|
||||||
|
|
||||||
|
### **The ability to add other server's local timeline to your timelines**
|
||||||
|
|
||||||
|
It can be accessed in the "Edit timelines" menu, where you can add a new "Community" to see other server's local posts!
|
||||||
|
|
||||||
|
### **View remote profiles**
|
||||||
|
|
||||||
|
You can now see all of a profile follows and followers, by directly loading them from the profile's home instance. In case of a failed lookup, the app will automatically fall back to the older method.
|
||||||
|
|
||||||
|
### **Translate posts easily**
|
||||||
|
|
||||||
|
Allows you to easily translate posts in another language with a translate button! Your instance must support translation, otherwise it will not work.
|
||||||
|
|
||||||
|
### **Show posts filtered with a warning**
|
||||||
|
|
||||||
|
Allows you to have filtered posts collapsed with a warning! As shown in the screenshots:
|
||||||
|
|
||||||
|
Before | After
|
||||||
|
:-------------------------:|:-------------------------:
|
||||||
|
 | 
|
||||||
|
|
||||||
|
|
||||||
|
### **Color themes**
|
||||||
|
|
||||||
|
Allows you to change theme within the app. Supports Material You, purple, pink, green, blue, red, orange, yellow and Nord!
|
||||||
|
|
||||||
### **Unlisted posting**
|
### **Unlisted posting**
|
||||||
|
|
||||||
<details>
|
**Allows you to post publicly without having your post show up in trends, hashtags or public timelines (i.e., in the tabs “Local”, “Community” and “Posts”).**
|
||||||
<p><summary>Allows you to post publicly without having your post show up in trends, hashtags or public timelines (i.e., in the tabs “Community”, “Federated” and “Posts”).</summary></p>
|
|
||||||
|
|
||||||
When posting with Unlisted visibility, your posts will still be publicly accessible in your profile. They will also be shown in people’s Home timelines, but only if they follow you or someone they follow reblogged/replied to your post.
|
When posting with Unlisted visibility, your posts will still be publicly accessible in your profile. They will also be shown in people’s Home timelines, but only if they follow you or someone they follow reposted/replied to your post.
|
||||||
|
|
||||||
The Mastodon documentation has some more information about [Unlisted posting](https://docs.joinmastodon.org/user/posting/#unlisted) and [Public timelines](https://docs.joinmastodon.org/user/network/#timelines).
|
The Mastodon documentation has some more information about [Unlisted posting](https://docs.joinmastodon.org/user/posting/#unlisted) and [Public timelines](https://docs.joinmastodon.org/user/network/#timelines).
|
||||||
</details>
|
|
||||||
|
|
||||||
### **Federated timeline**
|
### **Federated timeline**
|
||||||
|
|
||||||
<details>
|
**This allows you to chronologically see all Public posts from people on all other Fediverse neighborhoods your home instance is connected to.**
|
||||||
<p><summary>This allows you to chronologically see all Public posts from people on all other Fediverse neighborhoods your home instance is connected to.</summary></p>
|
|
||||||
|
|
||||||
Despite being one of the main features of federated social media, the Federated timeline wasn’t included in the official Mastodon app – supposedly, because this conflicts with Google’s safety requirements for apps on the Play Store.
|
Despite being one of the main features of federated social media, the Federated timeline wasn’t included in the official Mastodon app – supposedly, because this conflicts with Google’s safety requirements for apps on the Play Store.
|
||||||
|
|
||||||
That’s one of the reasons why choosing a small, **well-moderated instance is important**. Instance admins and moderators should always make sure to ban abusive users and stop federating with instances who platform them. On well-moderated instances, the Federated timeline can be a welcoming place to meet new people!
|
That’s one of the reasons why choosing a small, **well-moderated instance is important**. Instance admins and moderators should always make sure to ban abusive users and stop federating with instances who platform them. On well-moderated instances, the Federated timeline can be a welcoming place to meet new people!
|
||||||
</details>
|
|
||||||
|
|
||||||
### **Customizable timelines**
|
### **Image description viewer**
|
||||||
|
|
||||||
<details>
|
**Allows you to quickly check whether an image or video has an alternative text attached to it.**
|
||||||
<p><summary>You can customize Megalodon’s home tab and not only add local and federated timelines, but also pin lists and hashtags.</summary></p>
|
|
||||||
|
|
||||||
Even better: You can rename every timeline however you please and pick a distinct icon for each timeline. This way, you can pin the hashtag “#Caturday”, rename your timeline to “CUTENESS OVERLOAD” and set <img src="img/ic_fluent_animal_cat_24_regular.svg" alt="Cat icon from Microsoft Fluent UI icons"> as its icon. :3 You can find the timelines editor by opening your home tab, tapping the `⋮` button in the top right and going to “Edit timelines”.
|
This is important to **ensure the content you’re sharing is as accessible as possible** to people who can’t see the images and rely on software to read back the provided content descriptions. Thankfully, it’s quite common for people on the Fediverse to provide such alt texts, and hopefully things stay this way!
|
||||||
</details>
|
|
||||||
|
|
||||||
### **Draft and schedule posts**
|
### **Reminder to add alt text to attached media**
|
||||||
|
|
||||||
<details>
|
By default, Moshidon will show a warning to add alt text if your post has any attachments without any alt text. This is for better accessibility, and it can easily be bypassed and disabled in settings.
|
||||||
<p><summary>
|
|
||||||
Allows to prepare a post and schedule it to send it automatically at a specific time.</summary></p>
|
|
||||||
|
|
||||||
You can create drafts, edit them, send them manually later or set a scheduled date. Drafts are technically saved as scheduled posts, so you can view and edit them from other apps that support scheduled posts. Scheduled posts are handled by your home instance, so they'll work even if you uninstall Megalodon.
|
### **Pinning posts**
|
||||||
</details>
|
|
||||||
|
**This lets you can highlight important posts on your profile. A dedicated “Pinned” tab in people’s profiles shows all the posts they pinned.**
|
||||||
|
|
||||||
|
On the Fediverse, it’s quite common for people to pin posts they want others to read before following them. You can pin/unpin posts yourself by clicking the `⋯` button in the top right corner of your posts.
|
||||||
|
|
||||||
|
### **Bookmarks**
|
||||||
|
|
||||||
|
**They allow for quickly saving posts and viewing them through the Bookmarks button on the top right of your profile.**
|
||||||
|
|
||||||
|
To bookmark a post, press the button between the Favorite and Share buttons on the bottom of the post. Bookmarks are saved privately, so the post authors won’t know you saved their post – the list of bookmarked posts is only visible to you.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
### Google Play Store
|
**Press the download button above to download the APK. Open the downloaded file on your Android device to install it. Moshidon will automatically notify you about new updates inside the app.**
|
||||||
|
|
||||||
[https://play.google.com/store/apps/details?id=org.joinmastodon.android.sk](https://play.google.com/store/apps/details?id=org.joinmastodon.android.sk)
|
To install this app on your Android device, download the [latest release from GitHub](https://github.com/LucasGGamerM/moshidon/releases/latest/download/moshidon.apk) and open it. You might have to accept installing APK files from your browser when trying to install it. You can also take a look at all releases on the [Releases](https://github.com/LucasGGamerM/moshidon/releases) page.
|
||||||
|
|
||||||
<a href="https://play.google.com/store/apps/details?id=org.joinmastodon.android.sk"><img height="50" alt="Get it on Google Play" src="img/google-play-badge.png"></a>
|
Moshidon makes use of [Mastodon for Android](https://github.com/mastodon/mastodon-android)’s automatic update checker. Moshidon will check for new updates available on GitHub and offer to download and install them. You can also manually press “Check for updates” at the bottom of the settings page!
|
||||||
|
|
||||||
### F-Droid via IzzyOnDroid
|
|
||||||
|
|
||||||
[https://apt.izzysoft.de/fdroid/index/apk/org.joinmastodon.android.sk](https://apt.izzysoft.de/fdroid/index/apk/org.joinmastodon.android.sk)
|
|
||||||
|
|
||||||
<a href="https://apt.izzysoft.de/fdroid/index/apk/org.joinmastodon.android.sk"><img height="50" alt="Get it on IzzyOnDroid" src="img/izzy-badge.png"></a>
|
|
||||||
|
|
||||||
Note that you'll need to add Izzy's F-Droid repository to your F-Droid app first:
|
|
||||||
|
|
||||||
[`https://apt.izzysoft.de/fdroid/repo`](https://apt.izzysoft.de/fdroid/repo)
|
|
||||||
|
|
||||||
### F-Droid via saunarepo
|
|
||||||
|
|
||||||
[https://repo.the-sauna.icu](https://repo.the-sauna.icu/)
|
|
||||||
|
|
||||||
<a href="https://repo.the-sauna.icu"><img height="28" alt="Get it on SaunaRepo" src="img/saunarepo-badge.svg"></a>
|
|
||||||
|
|
||||||
### F-Droid
|
|
||||||
|
|
||||||
**[F-Droid.org?](https://f-droid.org)** Not yet, sorry!
|
|
||||||
|
|
||||||
If you want, you can help me figure out if something's missing in the [Issue #47: F-Droid.org](https://github.com/sk22/megalodon/issues/47)
|
|
||||||
|
|
||||||
### Direct
|
|
||||||
|
|
||||||
Press the download button to download the APK. Open the downloaded file on your Android device to install it. Megalodon will automatically notify you about new updates inside the app.
|
|
||||||
|
|
||||||
[](https://github.com/sk22/megalodon/releases/latest/download/megalodon.apk)
|
|
||||||
|
|
||||||
You might have to accept installing APK files from your browser when trying to install it. You can also take a look at all releases on the [Releases](https://github.com/sk22/megalodon/releases) page.
|
|
||||||
|
|
||||||
Megalodon makes use of [Mastodon for Android](https://github.com/mastodon/mastodon-android)’s automatic update checker. Megalodon will check for new updates available on GitHub and offer to download and install them. You can also manually press “Check for updates” at the bottom of the settings page!
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
|
Moshidon is also available in [IzzyOnDroid repo](https://apt.izzysoft.de/fdroid/index/apk/org.joinmastodon.android.moshinda), compatible with all F-Droid clients. The APK provided here is the same as the one included in the Releases.
|
||||||
|
|
||||||
## Release variants
|
## Release variants
|
||||||
|
|
||||||
All downloads can be found on the [Releases](https://github.com/sk22/megalodon/releases) page. When downloading a pre-release, expect to see unfinished features and bugs. If you don’t want that, just download the [latest full release](https://github.com/sk22/megalodon/releases/latest/download/megalodon.apk).
|
### Stable variant
|
||||||
|
|
||||||
**`megalodon.apk`**
|
All stable version downloads can be found on the [Releases](https://github.com/LucasGGamerM/moshidon/releases) page.
|
||||||
|
|
||||||
Variant with an integrated updater. If you download Megalodon from here (and not from an app store), just download the regular `megalodon.apk`.
|
**`moshidon.apk`**
|
||||||
|
|
||||||
**`upstream-1234abc.apk`**
|
Variant with an integrated updater. If you download Moshidon from here (and not from an app store), just download the regular `moshidon.apk`.
|
||||||
|
|
||||||
This is an **unmodified version** of the official [Mastodon for Android](https://github.com/mastodon/mastodon-android) app the respective Megalodon release is based on. Should you find any bugs in Megalodon (which you will), try to see if it occurs with this variant, too. The last 7 digits of the file name are important to know which version of the official app you're using.
|
### Nightly variant
|
||||||
|
|
||||||
<!-- **`megalodon-fdroid.apk`**
|
All nightly builds can be downloaded at [Nightly Releases](https://github.com/LucasGGamerM/moshidon-nightly/releases) page.
|
||||||
|
|
||||||
Variant without the integrated updater. This is the variant to be published to F-Droid.org where an integrated updater is not necessary. -->
|
**`moshidon-nightly.apk`**
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Contribution
|
|
||||||
|
|
||||||
### Translation
|
|
||||||
|
|
||||||
The translation for the base of the app is sourced from the upstream **Mastodon for Android** project, which you can contribute to on its Crowdin project: [https://crowdin.com/project/mastodon-for-android](https://crowdin.com/project/mastodon-for-android)
|
|
||||||
|
|
||||||
There's also a bunch of custom strings exclusive to this project that need to be translated. You can help translate **Megalodon** on Weblate: [https://translate.codeberg.org/projects/megalodon](https://translate.codeberg.org/projects/megalodon)
|
|
||||||
|
|
||||||
[](https://translate.codeberg.org/engage/megalodon)
|
|
||||||
|
|
||||||
|
Unstable variant with an integrated updater. It's for development and testing purposes. If you find any bugs with it, please file a bug report at our [issues](https://github.com/LucasGGamerM/moshidon/issues) page.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -131,16 +128,25 @@ There's also a bunch of custom strings exclusive to this project that need to be
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
|
* [Adding the ability to view other server's local timelines](https://github.com/LucasGGamerM/moshidon/tree/feature/local-timelines)
|
||||||
|
* [Adding the ability to load followers and following from remote instance](https://github.com/LucasGGamerM/moshidon/tree/feature/remote-followers)
|
||||||
|
* [Adding the ability to have filtered posts show with a warning](https://github.com/LucasGGamerM/moshidon/tree/feature/filters_again)
|
||||||
* [Add “Unlisted” as a post visibility option](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/enable-unlisted)
|
* [Add “Unlisted” as a post visibility option](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/enable-unlisted)
|
||||||
([Pull request](https://github.com/mastodon/mastodon-android/pull/103))
|
([Pull request](https://github.com/mastodon/mastodon-android/pull/103))
|
||||||
* [Add “Federation” tab and change Discover tab order](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/add-federated-timeline) ([Closes issue](https://github.com/mastodon/mastodon-android/issues/8))
|
* Adding a useful private profile note box
|
||||||
|
* Auto hiding the compose button on scroll
|
||||||
|
* Adding the ability to remind yourself to add alt text to images
|
||||||
|
* An indicator for if an image has alt text or not
|
||||||
|
* Adding the ability to have drafts
|
||||||
|
* Also adding the ability to view announcements from your instance
|
||||||
|
* Adding the ability to post for local timeline only (Only on instances that support it!)
|
||||||
* [Add image description button and viewer](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/display-alt-text) ([Pull request](https://github.com/mastodon/mastodon-android/pull/129))
|
* [Add image description button and viewer](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/display-alt-text) ([Pull request](https://github.com/mastodon/mastodon-android/pull/129))
|
||||||
* [Implement pinning posts and displaying pinned posts](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/pin-posts) ([Pull request](https://github.com/mastodon/mastodon-android/pull/140))
|
* [Implement pinning posts and displaying pinned posts](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/pin-posts) ([Pull request](https://github.com/mastodon/mastodon-android/pull/140))
|
||||||
* [Implement deleting and re-drafting](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/delete-redraft) ([Closes issue](https://github.com/mastodon/mastodon-android/issues/21))
|
* [Implement deleting and re-drafting](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/delete-redraft) ([Closes issue](https://github.com/mastodon/mastodon-android/issues/21))
|
||||||
* [Implement a bookmark button and list](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/bookmarks) ([Closes issue](https://github.com/mastodon/mastodon-android/issues/22))
|
* [Implement a bookmark button and list](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/bookmarks) ([Closes issue](https://github.com/mastodon/mastodon-android/issues/22))
|
||||||
* [Add “Check for update” button in addition to integrated update checker](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/check-for-update-button)
|
* [Add “Check for update” button in addition to integrated update checker](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/check-for-update-button)
|
||||||
* [Add “Mark media as sensitive” option](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/mark-media-as-sensitive)
|
* [Add “Mark media as sensitive” option](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/mark-media-as-sensitive)
|
||||||
* [Add settings to hide replies and reblogs from the timeline](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/filter-home-timeline) ([Pull request](https://github.com/mastodon/mastodon-android/pull/317))
|
* [Add settings to hide replies and reposts from the timeline](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/filter-home-timeline) ([Pull request](https://github.com/mastodon/mastodon-android/pull/317))
|
||||||
* [Follow and unfollow hashtags](https://github.com/sk22/megalodon/commit/7d38f031f197aa6cefaf53e39d929538689c1e4e) ([Closes issue](https://github.com/mastodon/mastodon-android/issues/233))
|
* [Follow and unfollow hashtags](https://github.com/sk22/megalodon/commit/7d38f031f197aa6cefaf53e39d929538689c1e4e) ([Closes issue](https://github.com/mastodon/mastodon-android/issues/233))
|
||||||
* [Notification bell for posts](https://github.com/sk22/megalodon/commit/b166ca705eb9169025ef32bbe6315b42491b57ea) ([Closes issue](https://github.com/mastodon/mastodon-android/issues/81))
|
* [Notification bell for posts](https://github.com/sk22/megalodon/commit/b166ca705eb9169025ef32bbe6315b42491b57ea) ([Closes issue](https://github.com/mastodon/mastodon-android/issues/81))
|
||||||
* [Viewing lists and adding/removing users from lists](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:list-timeline-views) based on [@obstsalatschuessel](https://github.com/obstsalatschuessel)'s [Pull request](https://github.com/mastodon/mastodon-android/pull/286)
|
* [Viewing lists and adding/removing users from lists](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:list-timeline-views) based on [@obstsalatschuessel](https://github.com/obstsalatschuessel)'s [Pull request](https://github.com/mastodon/mastodon-android/pull/286)
|
||||||
|
@ -150,27 +156,13 @@ There's also a bunch of custom strings exclusive to this project that need to be
|
||||||
* [Add notifications tab for posts](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/posts-notifications-tab)
|
* [Add notifications tab for posts](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/posts-notifications-tab)
|
||||||
* [Show visibility of original post when replying](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/display-reply-visibility)
|
* [Show visibility of original post when replying](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/display-reply-visibility)
|
||||||
* [Clickable reply/boost line above posts](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:clickable-boost-reply-line)
|
* [Clickable reply/boost line above posts](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:clickable-boost-reply-line)
|
||||||
* [Add push notification setting for post notifications](https://github.com/sk22/megalodon/commit/b190480d7739be47f23543d9e7644660f9b4b4ee)
|
* [Clickable reply line while replying to open original post](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/clickable-reply-line-compose)
|
||||||
* [Add option to allow voting for multiple options on polls](https://github.com/sk22/megalodon/commit/5b28468efd49387b4f8b83f142f3adf3104ca60c)
|
|
||||||
* [Add translate function](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/translate-button)
|
|
||||||
* [Add language selector](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/language-selector)
|
|
||||||
* [Implement deleting notifications](https://github.com/sk22/megalodon/commit/b0f9ce081f69f29ad59658fc00ca41372cd2677d) (disabled by default)
|
|
||||||
* [Long-click boost button to "quote" a post](https://github.com/sk22/megalodon/commit/b25a237c20c6a924ed4d9b357999867c3a32b32b)
|
|
||||||
* [Draft and schedule posts](https://github.com/sk22/megalodon/pull/217)
|
|
||||||
* [Display original post when replying](https://github.com/sk22/megalodon/commit/375f8ceb2747705fedf43686681cc0e0b812f899)
|
|
||||||
* [Display server announcements](https://github.com/sk22/megalodon/commit/84179bc207d6b69cc2a770a3c28fa0a39b0b54e8)
|
|
||||||
* [Create](https://github.com/sk22/megalodon/commit/294595513a45037359b31377aafc25ae5b58d8e7), [edit](https://github.com/sk22/megalodon/commit/d47797bf7ac8cff3f9ba1cfee219a1bb2af21da6) and [delete](https://github.com/sk22/megalodon/commit/54c29fd787fc2cd0dfd2787ad796b8190f795973) lists
|
|
||||||
* [Soft-blocking (by blocking and immediately unblocking)](https://github.com/sk22/megalodon/commit/e75d350b7a2709259e9fc5138e0e1f361bdb0972)
|
|
||||||
* [Pinnable custom timelines](https://github.com/sk22/megalodon/pull/338/commits)
|
|
||||||
* Support for local-only posts
|
|
||||||
* Support for copying the URL to posts/accounts/… in Pixel launcher’s Recent apps view
|
|
||||||
* Compatibility for Akkoma Bubble timeline
|
|
||||||
* Listings of followers/following/favorites/boosts can be loaded from the origin instance (there’s an option to disable this in in the settings)
|
|
||||||
* Allow opening posts/accounts in-app by sharing a URL/handle to Megalodon (Originally implemented in [Moshidon](https://github.com/LucasGGamerM/moshidon), [PR](https://github.com/sk22/megalodon/pull/531))
|
|
||||||
|
|
||||||
|
|
||||||
### Behavior
|
### Behavior
|
||||||
|
|
||||||
|
* Allow for confirmation before reblogging
|
||||||
|
* Adding a bottom option for the publish button, allowing for easier use on larger screens!
|
||||||
* [Make back button return to the home tab before exiting the app](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/back-returns-home) ([Closes issue](https://github.com/mastodon/mastodon-android/issues/118))
|
* [Make back button return to the home tab before exiting the app](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/back-returns-home) ([Closes issue](https://github.com/mastodon/mastodon-android/issues/118))
|
||||||
* [Always preserve content warnings when replying](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/always-preserve-cw) ([Closes issue](https://github.com/mastodon/mastodon-android/issues/113))
|
* [Always preserve content warnings when replying](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/always-preserve-cw) ([Closes issue](https://github.com/mastodon/mastodon-android/issues/113))
|
||||||
* [Display full image when adding image description](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/compose-image-description-full-image) ([Pull request](https://github.com/mastodon/mastodon-android/pull/182))
|
* [Display full image when adding image description](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/compose-image-description-full-image) ([Pull request](https://github.com/mastodon/mastodon-android/pull/182))
|
||||||
|
@ -178,22 +170,6 @@ There's also a bunch of custom strings exclusive to this project that need to be
|
||||||
* [Option to hide interaction numbers](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:settings/hide-interaction-numbers)
|
* [Option to hide interaction numbers](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:settings/hide-interaction-numbers)
|
||||||
* [Option to always reveal content warnings](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/cw-above-text)
|
* [Option to always reveal content warnings](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/cw-above-text)
|
||||||
* [Option to disable scrolling title bars](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:settings/disable-marquee)
|
* [Option to disable scrolling title bars](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:settings/disable-marquee)
|
||||||
* [No ellipsis for long poll answers](https://github.com/mastodon/mastodon-android/commit/c9aae828e2518adccdc092e41f8d1f0489636271)
|
|
||||||
* [Show poll vote button for multiple and single answer polls](https://github.com/mastodon/mastodon-android/commit/e14dfda2fdf32f0fa3043504ac5831683a87559a)
|
|
||||||
* [Show own vote after voting](https://github.com/mastodon/mastodon-android/commit/4ab9e25fec4fd9c10b7a8ddd1be522b3cc12cf28) ([Closes issue](https://github.com/mastodon/mastodon-android/commit/4ab9e25fec4fd9c10b7a8ddd1be522b3cc12cf28))
|
|
||||||
* [Make inline emoji search case-insensitive and don't only search from start of emoji names](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:better-inline-emoji-search) ([Pull request](https://github.com/mastodon/mastodon-android/pull/445))
|
|
||||||
* [Include subject line when sharing e.g. a website to Megalodon](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:external-share-include-subject)
|
|
||||||
* [Improve semantics for voting on polls (radio buttons and checkboxes)](https://github.com/sk22/megalodon/commit/6fd58c96827cb1d2da329cebdc170a1425dd18d7)
|
|
||||||
* [Copy post URL when long-pressing share button](https://github.com/sk22/megalodon/commit/ba36347f03278763ecec617b1ce57ba89db7be72)
|
|
||||||
* [Add option to disable swiping between tabs](https://github.com/sk22/megalodon/commit/1f20b21fc84bf006c1ec14bd2229cbfad5215ec8)
|
|
||||||
* [Resolve Fediverse links in the app](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/open-urls-in-app)
|
|
||||||
* [Preserve whitespaces in HTML](https://github.com/sk22/megalodon/commit/7d876bddc7a07d98f0fecbf62b13bdb9fcce3412)
|
|
||||||
* [Long-click to copy links](https://github.com/sk22/megalodon/commit/b32e32274923a94742a9926ef38785f746d41405)
|
|
||||||
* Improved filtering using Mastodon 4.0 API: [#202](https://github.com/sk22/megalodon/pull/202), [#212](https://github.com/sk22/megalodon/pull/212), [#255](https://github.com/sk22/megalodon/pull/255) by [@thiagojedi](https://github.com/thiagojedi)
|
|
||||||
* [Support admin notifications](https://github.com/sk22/megalodon/commit/c12a6eaee6b609bc53eb0a45d9199f37d5241801) and [notifications for edited reblogged posts](https://github.com/sk22/megalodon/commit/900e8fb2e9353002c16d15e06b78d2731e121601)
|
|
||||||
* [Android file opener added back in addition to image picker](https://github.com/sk22/megalodon/commit/3a6ace53d5ab01e28077c9c930cb6ed487b78031)
|
|
||||||
* [Replies are inserted below the replied-to post in thread view](https://github.com/sk22/megalodon/commit/87c37df370ec24aeea0d2dbaeb29468aa4fb5808)
|
|
||||||
* Option to auto-reveal equal content warnings in threads
|
|
||||||
|
|
||||||
|
|
||||||
### Visual
|
### Visual
|
||||||
|
@ -201,17 +177,6 @@ There's also a bunch of custom strings exclusive to this project that need to be
|
||||||
* [Custom extended footer redesign](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:compact-extended-footer)
|
* [Custom extended footer redesign](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:compact-extended-footer)
|
||||||
* [Improvements to the true black mode](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:true-black-improvements)
|
* [Improvements to the true black mode](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:true-black-improvements)
|
||||||
* [Profile header tweaks](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:ui/profile-header-tweaks)
|
* [Profile header tweaks](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:ui/profile-header-tweaks)
|
||||||
* [Custom color themes](https://github.com/sk22/megalodon/pull/124) by [@LucasGGamerM](https://github.com/LucasGGamerM)
|
|
||||||
* [Custom "megalodon" text logo](https://github.com/sk22/megalodon/commit/563afd487ca5c608cfbb00fa3909d3c27384acc0) by [@LucasGGamerM](https://github.com/LucasGGamerM)
|
|
||||||
* [Custom login screen](https://github.com/sk22/megalodon/commit/9bbf8c4618dbe13accaeb3b5482bf3fe88cac4c0)
|
|
||||||
* [More distinct filled boost icon](https://github.com/sk22/megalodon/commits/more-distinct-filled-boost-icon)
|
|
||||||
* Material You color theme by [@LucasGGamerM](https://github.com/LucasGGamerM)
|
|
||||||
* [Animations for interaction buttons](https://github.com/mastodon/mastodon-android/compare/master...sk22:megalodon:feature/animate-buttons)
|
|
||||||
* [Dedicated icons for different notification types](https://github.com/sk22/megalodon/pull/178) by [@florian-obernberger](https://github.com/florian-obernberger)
|
|
||||||
* Scale text according to system settings
|
|
||||||
* Header in timeline for followed hashtags
|
|
||||||
* [Indicator for missing alt texts](https://github.com/sk22/megalodon/commit/c0c276f03e793b78c478c17dfdef24a66ef7cedb)
|
|
||||||
* Visually grouped (by removing divider lines and reducing padding) threaded replies in thread view
|
|
||||||
|
|
||||||
|
|
||||||
## Building
|
## Building
|
||||||
|
@ -222,12 +187,18 @@ As this app is using Java 17 features, you need JDK 17 or newer to build it. Oth
|
||||||
./gradlew assembleRelease
|
./gradlew assembleRelease
|
||||||
```
|
```
|
||||||
|
|
||||||
Note that Megalodon might be depending on an in-development version of [AppKit](https://github.com/grishka/appkit) – a library by Mastodon for Android’s developer. In case the used AppKit version isn’t published to Maven Central yet, you might have to clone, build and publish it to your local Maven repository. For more information, see [this GitHub issue](https://github.com/mastodon/mastodon-android/issues/375#issuecomment-1507678585).
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
This project is released under the [GPL-3 License](./LICENSE).
|
This project is released under the [GPL-3 License](./LICENSE).
|
||||||
|
|
||||||
## Links
|
## Links
|
||||||
|
|
||||||
<a rel="me" href="https://floss.social/@megalodon">@megalodon<wbr>@floss.social</a>
|
[F.A.Q](FAQ.md)
|
||||||
|
|
||||||
|
[Official matrix chatroom:](https://matrix.to/#/#moshidon:floss.social) https://matrix.to/#/#moshidon:floss.social
|
||||||
|
|
||||||
|
[Moshidon roadmap](https://github.com/users/LucasGGamerM/projects/1)
|
||||||
|
|
||||||
|
<a rel="me" href="https://floss.social/@moshidon">@moshidon<wbr>@floss.social</a>
|
||||||
|
|
||||||
|
---
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
title: Megalodon
|
title: Moshidon
|
||||||
layout: default
|
layout: default
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Megalodon</title>
|
<title>Moshidon</title>
|
||||||
<link rel="icon" href="mastodon/src/main/res/mipmap-mdpi/ic_launcher_round.png">
|
<link rel="icon" href="mastodon/src/main/res/mipmap-mdpi/ic_launcher_round.png">
|
||||||
<link rel="me" href="https://floss.social/@megalodon">
|
<link rel="me" href="https://floss.social/@megalodon">
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.1.0/github-markdown.min.css">
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.1.0/github-markdown.min.css">
|
||||||
|
|
|
@ -9,6 +9,7 @@ buildscript {
|
||||||
includeModule 'com.github.UnifiedPush', 'android-connector'
|
includeModule 'com.github.UnifiedPush', 'android-connector'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mavenLocal()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:8.0.0'
|
classpath 'com.android.tools.build:gradle:8.0.0'
|
||||||
|
|
0
fix-metadata-markdown-lists.sh
Executable file → Normal file
|
@ -20,3 +20,4 @@ android.enableJetifier=false
|
||||||
android.defaults.buildfeatures.buildconfig=true
|
android.defaults.buildfeatures.buildconfig=true
|
||||||
android.nonTransitiveRClass=true
|
android.nonTransitiveRClass=true
|
||||||
android.nonFinalResIds=false
|
android.nonFinalResIds=false
|
||||||
|
org.gradle.configuration-cache=true
|
|
@ -11,16 +11,63 @@ java {
|
||||||
android {
|
android {
|
||||||
compileSdk 33
|
compileSdk 33
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
archivesBaseName = "megalodon"
|
manifestPlaceholders = [oAuthScheme:"moshidon-android-auth"]
|
||||||
applicationId "org.joinmastodon.android.sk"
|
archivesBaseName = "moshidon"
|
||||||
|
applicationId "org.joinmastodon.android.moshinda"
|
||||||
minSdk 23
|
minSdk 23
|
||||||
targetSdk 33
|
targetSdk 34
|
||||||
versionCode 110
|
versionCode 107
|
||||||
versionName "2.1.6+fork.110"
|
versionName "2.3.0+fork.107.moshinda"
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
resourceConfigurations += ['ar-rSA', 'ar-rDZ', 'be-rBY', 'bn-rBD', 'bs-rBA', 'ca-rES', 'cs-rCZ', 'da-rDK', 'de-rDE', 'el-rGR', 'es-rES', 'eu-rES', 'fa-rIR', 'fi-rFI', 'fil-rPH', 'fr-rFR', 'ga-rIE', 'gd-rGB', 'gl-rES', 'hi-rIN', 'hr-rHR', 'hu-rHU', 'hy-rAM', 'ig-rNG', 'in-rID', 'is-rIS', 'it-rIT', 'iw-rIL', 'ja-rJP', 'kab', 'ko-rKR', 'my-rMM', 'nl-rNL', 'no-rNO', 'oc-rFR', 'pl-rPL', 'pt-rBR', 'pt-rPT', 'ro-rRO', 'ru-rRU', 'si-rLK', 'sl-rSI', 'sv-rSE', 'th-rTH', 'tr-rTR', 'uk-rUA', 'ur-rIN', 'vi-rVN', 'zh-rCN', 'zh-rTW']
|
resourceConfigurations += ['ar-rSA', 'ar-rDZ', 'be-rBY', 'bn-rBD', 'bs-rBA', 'ca-rES', 'cs-rCZ', 'da-rDK', 'de-rDE', 'el-rGR', 'es-rES', 'eu-rES', 'fa-rIR', 'fi-rFI', 'fil-rPH', 'fr-rFR', 'ga-rIE', 'gd-rGB', 'gl-rES', 'hi-rIN', 'hr-rHR', 'hu-rHU', 'hy-rAM', 'ig-rNG', 'in-rID', 'is-rIS', 'it-rIT', 'iw-rIL', 'ja-rJP', 'kab', 'ko-rKR', 'my-rMM', 'nl-rNL', 'no-rNO', 'oc-rFR', 'pl-rPL', 'pt-rBR', 'pt-rPT', 'ro-rRO', 'ru-rRU', 'si-rLK', 'sl-rSI', 'sv-rSE', 'th-rTH', 'tr-rTR', 'uk-rUA', 'ur-rIN', 'vi-rVN', 'zh-rCN', 'zh-rTW']
|
||||||
}
|
}
|
||||||
|
|
||||||
|
signingConfigs {
|
||||||
|
nightly{
|
||||||
|
storeFile = file("keystore/nightly_keystore.jks")
|
||||||
|
storePassword System.getenv("SIGNING_STORE_PASSWORD")
|
||||||
|
if (storePassword == null) {
|
||||||
|
Properties properties = new Properties()
|
||||||
|
properties.load(project.rootProject.file('local.properties').newDataInputStream())
|
||||||
|
storePassword = properties.getProperty('SIGNING_STORE_PASSWORD')
|
||||||
|
}
|
||||||
|
keyAlias System.getenv("SIGNING_KEY_ALIAS")
|
||||||
|
if (keyAlias == null) {
|
||||||
|
Properties properties = new Properties()
|
||||||
|
properties.load(project.rootProject.file('local.properties').newDataInputStream())
|
||||||
|
keyAlias = properties.getProperty('SIGNING_KEY_ALIAS')
|
||||||
|
}
|
||||||
|
keyPassword System.getenv("SIGNING_KEY_PASSWORD")
|
||||||
|
if (keyPassword == null) {
|
||||||
|
Properties properties = new Properties()
|
||||||
|
properties.load(project.rootProject.file('local.properties').newDataInputStream())
|
||||||
|
keyPassword = properties.getProperty('SIGNING_KEY_PASSWORD')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// release{
|
||||||
|
// storeFile = file("keystore/release_keystore.jks")
|
||||||
|
// storePassword System.getenv("RELEASE_SIGNING_STORE_PASSWORD")
|
||||||
|
// if (storePassword == null) {
|
||||||
|
// Properties properties = new Properties()
|
||||||
|
// properties.load(project.rootProject.file('local.properties').newDataInputStream())
|
||||||
|
// storePassword = properties.getProperty('RELEASE_SIGNING_STORE_PASSWORD')
|
||||||
|
// }
|
||||||
|
// keyAlias System.getenv("RELEASE_SIGNING_KEY_ALIAS")
|
||||||
|
// if (keyAlias == null) {
|
||||||
|
// Properties properties = new Properties()
|
||||||
|
// properties.load(project.rootProject.file('local.properties').newDataInputStream())
|
||||||
|
// keyAlias = properties.getProperty('RELEASE_SIGNING_KEY_ALIAS')
|
||||||
|
// }
|
||||||
|
// keyPassword System.getenv("RELEASE_SIGNING_KEY_PASSWORD")
|
||||||
|
// if (keyPassword == null) {
|
||||||
|
// Properties properties = new Properties()
|
||||||
|
// properties.load(project.rootProject.file('local.properties').newDataInputStream())
|
||||||
|
// keyPassword = properties.getProperty('RELEASE_SIGNING_KEY_PASSWORD')
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
minifyEnabled true
|
minifyEnabled true
|
||||||
|
@ -31,9 +78,40 @@ android {
|
||||||
debuggable true
|
debuggable true
|
||||||
versionNameSuffix '-debug'
|
versionNameSuffix '-debug'
|
||||||
applicationIdSuffix '.debug'
|
applicationIdSuffix '.debug'
|
||||||
|
manifestPlaceholders = [oAuthScheme:"moshidon-android-debug-auth"]
|
||||||
|
}
|
||||||
|
githubRelease{
|
||||||
|
initWith release
|
||||||
|
}
|
||||||
|
nightly{
|
||||||
|
if(System.getenv("CURRENT_DATE") != null){
|
||||||
|
versionNameSuffix '-nightly+@' + System.getenv("CURRENT_DATE")
|
||||||
|
} else {
|
||||||
|
Properties properties = new Properties()
|
||||||
|
properties.load(project.rootProject.file('local.properties').newDataInputStream())
|
||||||
|
versionNameSuffix '-nightly+@' + properties.getProperty('CURRENT_DATE')
|
||||||
|
}
|
||||||
|
applicationIdSuffix '.nightly'
|
||||||
|
|
||||||
|
signingConfig signingConfigs.nightly
|
||||||
|
manifestPlaceholders = [oAuthScheme:"moshidon-android-nightly-auth"]
|
||||||
|
}
|
||||||
|
playRelease{
|
||||||
|
initWith release
|
||||||
|
minifyEnabled true
|
||||||
|
shrinkResources true
|
||||||
|
versionNameSuffix '-play'
|
||||||
|
}
|
||||||
|
githubRelease {
|
||||||
|
initWith release
|
||||||
|
versionNameSuffix '-github'
|
||||||
|
}
|
||||||
|
fdroidRelease {
|
||||||
|
initWith release
|
||||||
|
// The F-droid build system doesn't like this at all for some reason.
|
||||||
|
// versionNameSuffix '-fdroid'
|
||||||
|
// signingConfig signingConfigs.release
|
||||||
}
|
}
|
||||||
githubRelease { initWith release }
|
|
||||||
fdroidRelease { initWith release }
|
|
||||||
}
|
}
|
||||||
compileOptions {
|
compileOptions {
|
||||||
sourceCompatibility JavaVersion.VERSION_17
|
sourceCompatibility JavaVersion.VERSION_17
|
||||||
|
@ -45,7 +123,7 @@ android {
|
||||||
setRoot "src/github"
|
setRoot "src/github"
|
||||||
}
|
}
|
||||||
debug {
|
debug {
|
||||||
setRoot "src/github"
|
setRoot "src/debug"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
namespace 'org.joinmastodon.android'
|
namespace 'org.joinmastodon.android'
|
||||||
|
@ -69,7 +147,7 @@ dependencies {
|
||||||
implementation 'me.grishka.litex:viewpager:1.0.0'
|
implementation 'me.grishka.litex:viewpager:1.0.0'
|
||||||
implementation 'me.grishka.litex:viewpager2:1.0.0'
|
implementation 'me.grishka.litex:viewpager2:1.0.0'
|
||||||
implementation 'me.grishka.litex:palette:1.0.0'
|
implementation 'me.grishka.litex:palette:1.0.0'
|
||||||
implementation 'me.grishka.appkit:appkit:1.2.14'
|
implementation 'me.grishka.appkit:appkit:1.2.16'
|
||||||
implementation 'com.google.code.gson:gson:2.9.0'
|
implementation 'com.google.code.gson:gson:2.9.0'
|
||||||
implementation 'org.jsoup:jsoup:1.14.3'
|
implementation 'org.jsoup:jsoup:1.14.3'
|
||||||
implementation 'com.squareup:otto:1.3.8'
|
implementation 'com.squareup:otto:1.3.8'
|
||||||
|
|
7
mastodon/proguard-rules.pro
vendored
|
@ -45,6 +45,13 @@
|
||||||
|
|
||||||
-keepattributes LineNumberTable
|
-keepattributes LineNumberTable
|
||||||
|
|
||||||
|
-keepattributes *
|
||||||
|
-keep,allowobfuscation,allowshrinking class com.google.gson.reflect.TypeToken
|
||||||
|
-keep,allowobfuscation,allowshrinking class * extends com.google.gson.reflect.TypeToken
|
||||||
|
|
||||||
|
#-keep class javax.** { *; }
|
||||||
|
-keep class org.joinmastodon.android.** { *; }
|
||||||
|
|
||||||
# Parceler library
|
# Parceler library
|
||||||
-keep interface org.parceler.Parcel
|
-keep interface org.parceler.Parcel
|
||||||
-keep @org.parceler.Parcel class * { *; }
|
-keep @org.parceler.Parcel class * { *; }
|
||||||
|
|
|
@ -1,81 +0,0 @@
|
||||||
package org.joinmastodon.android.utils;
|
|
||||||
|
|
||||||
import static org.joinmastodon.android.model.FilterAction.*;
|
|
||||||
import static org.joinmastodon.android.model.FilterContext.*;
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import org.joinmastodon.android.model.LegacyFilter;
|
|
||||||
import org.joinmastodon.android.model.Status;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class StatusFilterPredicateTest {
|
|
||||||
|
|
||||||
private static final LegacyFilter hideMeFilter = new LegacyFilter(), warnMeFilter = new LegacyFilter();
|
|
||||||
private static final List<LegacyFilter> allFilters = List.of(hideMeFilter, warnMeFilter);
|
|
||||||
|
|
||||||
private static final Status
|
|
||||||
hideInHomePublic = Status.ofFake(null, "hide me, please", Instant.now()),
|
|
||||||
warnInHomePublic = Status.ofFake(null, "display me with a warning", Instant.now());
|
|
||||||
|
|
||||||
static {
|
|
||||||
hideMeFilter.phrase = "hide me";
|
|
||||||
hideMeFilter.filterAction = HIDE;
|
|
||||||
hideMeFilter.context = EnumSet.of(PUBLIC, HOME);
|
|
||||||
|
|
||||||
warnMeFilter.phrase = "warning";
|
|
||||||
warnMeFilter.filterAction = WARN;
|
|
||||||
warnMeFilter.context = EnumSet.of(PUBLIC, HOME);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHide() {
|
|
||||||
assertFalse("should not pass because matching filter applies to given context",
|
|
||||||
new StatusFilterPredicate(allFilters, HOME).test(hideInHomePublic));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHideRegardlessOfContext() {
|
|
||||||
assertTrue("filters without context should always pass",
|
|
||||||
new StatusFilterPredicate(allFilters, null).test(hideInHomePublic));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHideInDifferentContext() {
|
|
||||||
assertTrue("should pass because matching filter does not apply to given context",
|
|
||||||
new StatusFilterPredicate(allFilters, THREAD).test(hideInHomePublic));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHideWithWarningText() {
|
|
||||||
assertTrue("should pass because matching filter is for warnings",
|
|
||||||
new StatusFilterPredicate(allFilters, HOME).test(warnInHomePublic));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testWarn() {
|
|
||||||
assertFalse("should not pass because filter applies to given context",
|
|
||||||
new StatusFilterPredicate(allFilters, HOME, WARN).test(warnInHomePublic));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testWarnRegardlessOfContext() {
|
|
||||||
assertTrue("filters without context should always pass",
|
|
||||||
new StatusFilterPredicate(allFilters, null, WARN).test(warnInHomePublic));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testWarnInDifferentContext() {
|
|
||||||
assertTrue("should pass because filter does not apply to given context",
|
|
||||||
new StatusFilterPredicate(allFilters, THREAD, WARN).test(warnInHomePublic));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testWarnWithHideText() {
|
|
||||||
assertTrue("should pass because matching filter is for hiding",
|
|
||||||
new StatusFilterPredicate(allFilters, HOME, WARN).test(hideInHomePublic));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,9 +1,14 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
package="org.joinmastodon.android">
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
|
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
|
||||||
|
|
||||||
<application>
|
|
||||||
|
<application
|
||||||
|
tools:replace="android:label"
|
||||||
|
android:label="@string/mo_app_name_debug">
|
||||||
<!-- <receiver android:name=".updater.GithubSelfUpdaterImpl$InstallerStatusReceiver" android:exported="false"/>-->
|
<!-- <receiver android:name=".updater.GithubSelfUpdaterImpl$InstallerStatusReceiver" android:exported="false"/>-->
|
||||||
<!-- <receiver android:name=".updater.GithubSelfUpdaterImpl$AfterUpdateRestartReceiver" android:exported="true" android:enabled="false">-->
|
<!-- <receiver android:name=".updater.GithubSelfUpdaterImpl$AfterUpdateRestartReceiver" android:exported="true" android:enabled="false">-->
|
||||||
<!-- <intent-filter>-->
|
<!-- <intent-filter>-->
|
|
@ -0,0 +1,378 @@
|
||||||
|
package org.joinmastodon.android.updater;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.DownloadManager;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.pm.PackageInstaller;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
|
||||||
|
import org.joinmastodon.android.BuildConfig;
|
||||||
|
import org.joinmastodon.android.E;
|
||||||
|
import org.joinmastodon.android.GlobalUserPreferences;
|
||||||
|
import org.joinmastodon.android.MastodonApp;
|
||||||
|
import org.joinmastodon.android.R;
|
||||||
|
import org.joinmastodon.android.api.MastodonAPIController;
|
||||||
|
import org.joinmastodon.android.events.SelfUpdateStateChangedEvent;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import androidx.annotation.Keep;
|
||||||
|
import okhttp3.Call;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.Response;
|
||||||
|
|
||||||
|
@Keep
|
||||||
|
public class GithubSelfUpdaterImpl extends GithubSelfUpdater{
|
||||||
|
private static final long CHECK_PERIOD=6*3600*1000L;
|
||||||
|
private static final String TAG="GithubSelfUpdater";
|
||||||
|
|
||||||
|
private UpdateState state=UpdateState.NO_UPDATE;
|
||||||
|
private UpdateInfo info;
|
||||||
|
private long downloadID;
|
||||||
|
private BroadcastReceiver downloadCompletionReceiver=new BroadcastReceiver(){
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent){
|
||||||
|
if(downloadID!=0 && intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0)==downloadID){
|
||||||
|
MastodonApp.context.unregisterReceiver(this);
|
||||||
|
setState(UpdateState.DOWNLOADED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public GithubSelfUpdaterImpl(){
|
||||||
|
SharedPreferences prefs=getPrefs();
|
||||||
|
int checkedByBuild=prefs.getInt("checkedByBuild", 0);
|
||||||
|
if(prefs.contains("version") && checkedByBuild==BuildConfig.VERSION_CODE){
|
||||||
|
info=new UpdateInfo();
|
||||||
|
info.version=prefs.getString("version", null);
|
||||||
|
info.size=prefs.getLong("apkSize", 0);
|
||||||
|
info.changelog=prefs.getString("changelog", null);
|
||||||
|
downloadID=prefs.getLong("downloadID", 0);
|
||||||
|
if(downloadID==0 || !getUpdateApkFile().exists()){
|
||||||
|
state=UpdateState.UPDATE_AVAILABLE;
|
||||||
|
}else{
|
||||||
|
DownloadManager dm=MastodonApp.context.getSystemService(DownloadManager.class);
|
||||||
|
state=dm.getUriForDownloadedFile(downloadID)==null ? UpdateState.DOWNLOADING : UpdateState.DOWNLOADED;
|
||||||
|
if(state==UpdateState.DOWNLOADING){
|
||||||
|
MastodonApp.context.registerReceiver(downloadCompletionReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else if(checkedByBuild!=BuildConfig.VERSION_CODE && checkedByBuild>0){
|
||||||
|
// We are in a new version, running for the first time after update. Gotta clean things up.
|
||||||
|
long id=getPrefs().getLong("downloadID", 0);
|
||||||
|
if(id!=0){
|
||||||
|
MastodonApp.context.getSystemService(DownloadManager.class).remove(id);
|
||||||
|
}
|
||||||
|
getUpdateApkFile().delete();
|
||||||
|
getPrefs().edit()
|
||||||
|
.remove("apkSize")
|
||||||
|
.remove("version")
|
||||||
|
.remove("apkURL")
|
||||||
|
.remove("checkedByBuild")
|
||||||
|
.remove("downloadID")
|
||||||
|
.remove("changelog")
|
||||||
|
.apply();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private SharedPreferences getPrefs(){
|
||||||
|
return MastodonApp.context.getSharedPreferences("githubUpdater", Context.MODE_PRIVATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void maybeCheckForUpdates(){
|
||||||
|
if(state!=UpdateState.NO_UPDATE && state!=UpdateState.UPDATE_AVAILABLE)
|
||||||
|
return;
|
||||||
|
long timeSinceLastCheck=System.currentTimeMillis()-getPrefs().getLong("lastCheck", CHECK_PERIOD);
|
||||||
|
if(timeSinceLastCheck>=CHECK_PERIOD){
|
||||||
|
setState(UpdateState.CHECKING);
|
||||||
|
MastodonAPIController.runInBackground(this::actuallyCheckForUpdates);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void checkForUpdates() {
|
||||||
|
setState(UpdateState.CHECKING);
|
||||||
|
MastodonAPIController.runInBackground(this::actuallyCheckForUpdates);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void actuallyCheckForUpdates(){
|
||||||
|
Request req=new Request.Builder()
|
||||||
|
.url("https://api.github.com/repos/LucasGGamerM/moshidon/releases")
|
||||||
|
.build();
|
||||||
|
Call call=MastodonAPIController.getHttpClient().newCall(req);
|
||||||
|
try(Response resp=call.execute()){
|
||||||
|
JsonArray arr=JsonParser.parseReader(resp.body().charStream()).getAsJsonArray();
|
||||||
|
for (JsonElement jsonElement : arr) {
|
||||||
|
JsonObject obj = jsonElement.getAsJsonObject();
|
||||||
|
if (obj.get("prerelease").getAsBoolean() && !GlobalUserPreferences.enablePreReleases) continue;
|
||||||
|
|
||||||
|
String tag=obj.get("tag_name").getAsString();
|
||||||
|
String changelog=obj.get("body").getAsString();
|
||||||
|
Pattern pattern=Pattern.compile("v?(\\d+)\\.(\\d+)\\.(\\d+)\\+fork\\.(\\d+)");
|
||||||
|
Matcher matcher=pattern.matcher(tag);
|
||||||
|
if(!matcher.find()){
|
||||||
|
Log.w(TAG, "actuallyCheckForUpdates: release tag has wrong format: "+tag);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int newMajor=Integer.parseInt(matcher.group(1)),
|
||||||
|
newMinor=Integer.parseInt(matcher.group(2)),
|
||||||
|
newRevision=Integer.parseInt(matcher.group(3)),
|
||||||
|
newForkNumber=Integer.parseInt(matcher.group(4));
|
||||||
|
matcher=pattern.matcher(BuildConfig.VERSION_NAME);
|
||||||
|
String[] currentParts=BuildConfig.VERSION_NAME.split("[.+]");
|
||||||
|
if(!matcher.find()){
|
||||||
|
Log.w(TAG, "actuallyCheckForUpdates: current version has wrong format: "+BuildConfig.VERSION_NAME);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int curMajor=Integer.parseInt(matcher.group(1)),
|
||||||
|
curMinor=Integer.parseInt(matcher.group(2)),
|
||||||
|
curRevision=Integer.parseInt(matcher.group(3)),
|
||||||
|
curForkNumber=Integer.parseInt(matcher.group(4));
|
||||||
|
long newVersion=((long)newMajor << 32) | ((long)newMinor << 16) | newRevision;
|
||||||
|
long curVersion=((long)curMajor << 32) | ((long)curMinor << 16) | curRevision;
|
||||||
|
if(newVersion>curVersion || newForkNumber>curForkNumber){
|
||||||
|
String version=newMajor+"."+newMinor+"."+newRevision+"+fork."+newForkNumber;
|
||||||
|
Log.d(TAG, "actuallyCheckForUpdates: new version: "+version);
|
||||||
|
for(JsonElement el:obj.getAsJsonArray("assets")){
|
||||||
|
JsonObject asset=el.getAsJsonObject();
|
||||||
|
if("moshidon.apk".equals(asset.get("name").getAsString()) && "application/vnd.android.package-archive".equals(asset.get("content_type").getAsString()) && "uploaded".equals(asset.get("state").getAsString())){
|
||||||
|
long size=asset.get("size").getAsLong();
|
||||||
|
String url=asset.get("browser_download_url").getAsString();
|
||||||
|
|
||||||
|
UpdateInfo info=new UpdateInfo();
|
||||||
|
info.size=size;
|
||||||
|
info.version=version;
|
||||||
|
info.changelog=changelog;
|
||||||
|
this.info=info;
|
||||||
|
|
||||||
|
getPrefs().edit()
|
||||||
|
.putLong("apkSize", size)
|
||||||
|
.putString("version", version)
|
||||||
|
.putString("apkURL", url)
|
||||||
|
.putString("changelog", changelog)
|
||||||
|
.putInt("checkedByBuild", BuildConfig.VERSION_CODE)
|
||||||
|
.remove("downloadID")
|
||||||
|
.apply();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
getPrefs().edit().putLong("lastCheck", System.currentTimeMillis()).apply();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}catch(Exception x){
|
||||||
|
Log.w(TAG, "actuallyCheckForUpdates", x);
|
||||||
|
}finally{
|
||||||
|
setState(info==null ? UpdateState.NO_UPDATE : UpdateState.UPDATE_AVAILABLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setState(UpdateState state){
|
||||||
|
this.state=state;
|
||||||
|
E.post(new SelfUpdateStateChangedEvent(state));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UpdateState getState(){
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UpdateInfo getUpdateInfo(){
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getUpdateApkFile(){
|
||||||
|
return new File(MastodonApp.context.getExternalCacheDir(), "update.apk");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void downloadUpdate(){
|
||||||
|
if(state==UpdateState.DOWNLOADING)
|
||||||
|
throw new IllegalStateException();
|
||||||
|
DownloadManager dm=MastodonApp.context.getSystemService(DownloadManager.class);
|
||||||
|
MastodonApp.context.registerReceiver(downloadCompletionReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
|
||||||
|
downloadID=dm.enqueue(
|
||||||
|
new DownloadManager.Request(Uri.parse(getPrefs().getString("apkURL", null)))
|
||||||
|
.setDestinationUri(Uri.fromFile(getUpdateApkFile()))
|
||||||
|
);
|
||||||
|
getPrefs().edit().putLong("downloadID", downloadID).apply();
|
||||||
|
setState(UpdateState.DOWNLOADING);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void installUpdate(Activity activity){
|
||||||
|
if(state!=UpdateState.DOWNLOADED)
|
||||||
|
throw new IllegalStateException();
|
||||||
|
Uri uri;
|
||||||
|
Intent intent=new Intent(Intent.ACTION_INSTALL_PACKAGE);
|
||||||
|
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.N){
|
||||||
|
uri=new Uri.Builder().scheme("content").authority(activity.getPackageName()+".self_update_provider").path("update.apk").build();
|
||||||
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
|
}else{
|
||||||
|
uri=Uri.fromFile(getUpdateApkFile());
|
||||||
|
}
|
||||||
|
intent.setDataAndType(uri, "application/vnd.android.package-archive");
|
||||||
|
activity.startActivity(intent);
|
||||||
|
|
||||||
|
// TODO figure out how to restart the app when updating via this new API
|
||||||
|
/*
|
||||||
|
PackageInstaller installer=activity.getPackageManager().getPackageInstaller();
|
||||||
|
try{
|
||||||
|
final int sid=installer.createSession(new PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL));
|
||||||
|
installer.registerSessionCallback(new PackageInstaller.SessionCallback(){
|
||||||
|
@Override
|
||||||
|
public void onCreated(int i){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBadgingChanged(int i){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActiveChanged(int i, boolean b){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProgressChanged(int id, float progress){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFinished(int id, boolean success){
|
||||||
|
activity.getPackageManager().setComponentEnabledSetting(new ComponentName(activity, AfterUpdateRestartReceiver.class), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
activity.getPackageManager().setComponentEnabledSetting(new ComponentName(activity, AfterUpdateRestartReceiver.class), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
|
||||||
|
PackageInstaller.Session session=installer.openSession(sid);
|
||||||
|
try(OutputStream out=session.openWrite("mastodon.apk", 0, info.size); InputStream in=new FileInputStream(getUpdateApkFile())){
|
||||||
|
byte[] buffer=new byte[16384];
|
||||||
|
int read;
|
||||||
|
while((read=in.read(buffer))>0){
|
||||||
|
out.write(buffer, 0, read);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// PendingIntent intent=PendingIntent.getBroadcast(activity, 1, new Intent(activity, InstallerStatusReceiver.class), PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_MUTABLE);
|
||||||
|
PendingIntent intent=PendingIntent.getActivity(activity, 1, new Intent(activity, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
session.commit(intent.getIntentSender());
|
||||||
|
}catch(IOException x){
|
||||||
|
Log.w(TAG, "installUpdate", x);
|
||||||
|
Toast.makeText(activity, x.getMessage(), Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getDownloadProgress(){
|
||||||
|
if(state!=UpdateState.DOWNLOADING)
|
||||||
|
throw new IllegalStateException();
|
||||||
|
DownloadManager dm=MastodonApp.context.getSystemService(DownloadManager.class);
|
||||||
|
try(Cursor cursor=dm.query(new DownloadManager.Query().setFilterById(downloadID))){
|
||||||
|
if(cursor.moveToFirst()){
|
||||||
|
long loaded=cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
|
||||||
|
long total=cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));
|
||||||
|
// Log.d(TAG, "getDownloadProgress: "+loaded+" of "+total);
|
||||||
|
return total>0 ? (float)loaded/total : 0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cancelDownload(){
|
||||||
|
if(state!=UpdateState.DOWNLOADING)
|
||||||
|
throw new IllegalStateException();
|
||||||
|
DownloadManager dm=MastodonApp.context.getSystemService(DownloadManager.class);
|
||||||
|
dm.remove(downloadID);
|
||||||
|
downloadID=0;
|
||||||
|
getPrefs().edit().remove("downloadID").apply();
|
||||||
|
setState(UpdateState.UPDATE_AVAILABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleIntentFromInstaller(Intent intent, Activity activity){
|
||||||
|
int status=intent.getIntExtra(PackageInstaller.EXTRA_STATUS, 0);
|
||||||
|
if(status==PackageInstaller.STATUS_PENDING_USER_ACTION){
|
||||||
|
Intent confirmIntent=intent.getParcelableExtra(Intent.EXTRA_INTENT);
|
||||||
|
activity.startActivity(confirmIntent);
|
||||||
|
}else if(status!=PackageInstaller.STATUS_SUCCESS){
|
||||||
|
String msg=intent.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE);
|
||||||
|
Toast.makeText(activity, activity.getString(R.string.error)+":\n"+msg, Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reset(){
|
||||||
|
getPrefs().edit().clear().apply();
|
||||||
|
File apk=getUpdateApkFile();
|
||||||
|
if(apk.exists())
|
||||||
|
apk.delete();
|
||||||
|
state=UpdateState.NO_UPDATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*public static class InstallerStatusReceiver extends BroadcastReceiver{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent){
|
||||||
|
int status=intent.getIntExtra(PackageInstaller.EXTRA_STATUS, 0);
|
||||||
|
if(status==PackageInstaller.STATUS_PENDING_USER_ACTION){
|
||||||
|
Intent confirmIntent=intent.getParcelableExtra(Intent.EXTRA_INTENT);
|
||||||
|
context.startActivity(confirmIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||||
|
}else if(status!=PackageInstaller.STATUS_SUCCESS){
|
||||||
|
String msg=intent.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE);
|
||||||
|
Toast.makeText(context, context.getString(R.string.error)+":\n"+msg, Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class AfterUpdateRestartReceiver extends BroadcastReceiver{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent){
|
||||||
|
if(Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())){
|
||||||
|
context.getPackageManager().setComponentEnabledSetting(new ComponentName(context, AfterUpdateRestartReceiver.class), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
|
||||||
|
Toast.makeText(context, R.string.update_installed, Toast.LENGTH_SHORT).show();
|
||||||
|
Intent restartIntent=new Intent(context, MainActivity.class)
|
||||||
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
|
.setPackage(context.getPackageName());
|
||||||
|
if(Build.VERSION.SDK_INT<Build.VERSION_CODES.P){
|
||||||
|
context.startActivity(restartIntent);
|
||||||
|
}else{
|
||||||
|
// Bypass activity starting restrictions by starting it from a notification
|
||||||
|
NotificationManager nm=context.getSystemService(NotificationManager.class);
|
||||||
|
NotificationChannel chan=new NotificationChannel("selfUpdateRestart", context.getString(R.string.update_installed), NotificationManager.IMPORTANCE_HIGH);
|
||||||
|
nm.createNotificationChannel(chan);
|
||||||
|
Notification n=new Notification.Builder(context, "selfUpdateRestart")
|
||||||
|
.setContentTitle(context.getString(R.string.update_installed))
|
||||||
|
.setContentIntent(PendingIntent.getActivity(context, 1, restartIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE))
|
||||||
|
.setFullScreenIntent(PendingIntent.getActivity(context, 1, restartIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE), true)
|
||||||
|
.setSmallIcon(R.drawable.ic_ntf_logo)
|
||||||
|
.build();
|
||||||
|
nm.notify(1, n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
package org.joinmastodon.android.updater;
|
||||||
|
|
||||||
|
import android.content.ContentProvider;
|
||||||
|
import android.content.ContentValues;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.ParcelFileDescriptor;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
public class SelfUpdateContentProvider extends ContentProvider{
|
||||||
|
@Override
|
||||||
|
public boolean onCreate(){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getType(@NonNull Uri uri){
|
||||||
|
if(isCorrectUri(uri))
|
||||||
|
return "application/vnd.android.package-archive";
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public Uri insert(@NonNull Uri uri, @Nullable ContentValues values){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int delete(@NonNull Uri uri, @Nullable String selection, @Nullable String[] selectionArgs){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int update(@NonNull Uri uri, @Nullable ContentValues values, @Nullable String selection, @Nullable String[] selectionArgs){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode) throws FileNotFoundException{
|
||||||
|
if(isCorrectUri(uri)){
|
||||||
|
return ParcelFileDescriptor.open(((GithubSelfUpdaterImpl)GithubSelfUpdater.getInstance()).getUpdateApkFile(), ParcelFileDescriptor.MODE_READ_ONLY);
|
||||||
|
}
|
||||||
|
throw new FileNotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isCorrectUri(Uri uri){
|
||||||
|
return "/update.apk".equals(uri.getPath());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="20dp" android:height="20dp" android:viewportWidth="20" android:viewportHeight="20">
|
||||||
|
<path android:pathData="M3.897 4.054L3.97 3.97c0.266-0.267 0.683-0.29 0.976-0.073L5.03 3.97 10 8.939l4.97-4.97c0.266-0.266 0.683-0.29 0.976-0.072L16.03 3.97c0.267 0.266 0.29 0.683 0.073 0.976L16.03 5.03 11.061 10l4.97 4.97c0.266 0.266 0.29 0.683 0.072 0.976L16.03 16.03c-0.266 0.267-0.683 0.29-0.976 0.073L14.97 16.03 10 11.061l-4.97 4.97c-0.266 0.266-0.683 0.29-0.976 0.072L3.97 16.03c-0.267-0.266-0.29-0.683-0.073-0.976L3.97 14.97 8.939 10l-4.97-4.97C3.704 4.764 3.68 4.347 3.898 4.054L3.97 3.97 3.897 4.054z" android:fillColor="@color/fluent_default_icon_tint"/>
|
||||||
|
</vector>
|
|
@ -0,0 +1,3 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
|
||||||
|
<path android:pathData="M22 6.5c0 3.038-2.462 5.5-5.5 5.5S11 9.538 11 6.5 13.462 1 16.5 1 22 3.462 22 6.5zm-7.146-2.354c-0.196-0.195-0.512-0.195-0.708 0-0.195 0.196-0.195 0.512 0 0.708L15.793 6.5l-1.647 1.646c-0.195 0.196-0.195 0.512 0 0.707 0.196 0.196 0.512 0.196 0.708 0L16.5 7.208l1.646 1.647c0.196 0.195 0.512 0.195 0.708 0 0.195-0.196 0.195-0.512 0-0.707L17.207 6.5l1.647-1.646c0.195-0.196 0.195-0.512 0-0.708-0.196-0.195-0.512-0.195-0.708 0L16.5 5.793l-1.646-1.647zM19.5 14v-1.732c0.551-0.287 1.056-0.651 1.5-1.078v7.56c0 1.733-1.357 3.15-3.066 3.245L17.75 22H6.25c-1.733 0-3.15-1.357-3.245-3.066L3 18.75V7.25C3 5.517 4.356 4.1 6.066 4.005L6.25 4h4.248c-0.198 0.474-0.34 0.977-0.422 1.5H6.25c-0.918 0-1.671 0.707-1.744 1.606L4.5 7.25V14H9c0.38 0 0.694 0.282 0.743 0.648L9.75 14.75C9.75 15.993 10.757 17 12 17c1.19 0 2.166-0.925 2.245-2.096l0.005-0.154c0-0.38 0.282-0.694 0.648-0.743L15 14h4.5zm-15 1.5v3.25c0 0.918 0.707 1.671 1.606 1.744L6.25 20.5h11.5c0.918 0 1.671-0.707 1.744-1.607L19.5 18.75V15.5h-3.825c-0.335 1.648-1.75 2.904-3.475 2.995L12 18.5c-1.747 0-3.215-1.195-3.632-2.812L8.325 15.5H4.5z" android:fillColor="@color/fluent_default_icon_tint"/>
|
||||||
|
</vector>
|
|
@ -0,0 +1,3 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="28dp" android:height="28dp" android:viewportWidth="28" android:viewportHeight="28">
|
||||||
|
<path android:pathData="M26 7.5c0 3.59-2.91 6.5-6.5 6.5S13 11.09 13 7.5 15.91 1 19.5 1 26 3.91 26 7.5zm-9.146-3.354c-0.196-0.195-0.512-0.195-0.708 0-0.195 0.196-0.195 0.512 0 0.708L18.793 7.5l-2.647 2.646c-0.195 0.196-0.195 0.512 0 0.708 0.196 0.195 0.512 0.195 0.708 0L19.5 8.207l2.646 2.647c0.196 0.195 0.512 0.195 0.708 0 0.195-0.196 0.195-0.512 0-0.708L20.207 7.5l2.647-2.646c0.195-0.196 0.195-0.512 0-0.708-0.196-0.195-0.512-0.195-0.708 0L19.5 6.793l-2.646-2.647zM25 22.75V12.6c-0.443 0.476-0.947 0.896-1.5 1.245V16h-6l-0.102 0.007c-0.366 0.05-0.648 0.363-0.648 0.743 0 1.519-1.231 2.75-2.75 2.75s-2.75-1.231-2.75-2.75l-0.007-0.102C11.193 16.282 10.88 16 10.5 16h-6V7.25c0-0.966 0.784-1.75 1.75-1.75h6.02c0.145-0.525 0.345-1.028 0.595-1.5H6.25C4.455 4 3 5.455 3 7.25v15.5C3 24.545 4.455 26 6.25 26h15.5c1.795 0 3.25-1.455 3.25-3.25zm-20.5 0V17.5h5.316l0.041 0.204C10.291 19.592 11.982 21 14 21l0.215-0.005c1.994-0.1 3.627-1.574 3.969-3.495H23.5v5.25c0 0.966-0.784 1.75-1.75 1.75H6.25c-0.966 0-1.75-0.784-1.75-1.75z" android:fillColor="@color/fluent_default_icon_tint"/>
|
||||||
|
</vector>
|
|
@ -0,0 +1,3 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="20dp" android:height="20dp" android:viewportWidth="20" android:viewportHeight="20">
|
||||||
|
<path android:pathData="M10 2c4.418 0 8 3.582 8 8 0 2.706-1.142 4.5-3 4.5-1.226 0-2.14-0.781-2.62-2.09C11.784 13.393 10.781 14 9.5 14 7.36 14 6 12.307 6 10c0-2.337 1.313-4 3.5-4 1.052 0 1.901 0.385 2.5 1.044V6.5C12 6.224 12.224 6 12.5 6c0.245 0 0.45 0.177 0.492 0.41L13 6.5V10c0 2.223 0.813 3.5 2 3.5s2-1.277 2-3.5c0-3.866-3.134-7-7-7s-7 3.134-7 7 3.134 7 7 7c0.823 0 1.626-0.142 2.383-0.416 0.26-0.094 0.547 0.04 0.64 0.3 0.095 0.26-0.04 0.546-0.3 0.64C11.859 17.838 10.94 18 10 18c-4.418 0-8-3.582-8-8s3.582-8 8-8zM9.5 7C7.924 7 7 8.17 7 10c0 1.797 0.966 3 2.5 3s2.5-1.203 2.5-3c0-1.83-0.924-3-2.5-3z" android:fillColor="@color/fluent_default_icon_tint"/>
|
||||||
|
</vector>
|
|
@ -0,0 +1,3 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
|
||||||
|
<path android:pathData="M6.25 4.5C5.283 4.5 4.5 5.284 4.5 6.25v11.5c0 0.966 0.783 1.75 1.75 1.75h11.5c0.966 0 1.75-0.784 1.75-1.75v-4c0-0.414 0.335-0.75 0.75-0.75 0.414 0 0.75 0.336 0.75 0.75v4c0 1.795-1.456 3.25-3.25 3.25H6.25C4.455 21 3 19.545 3 17.75V6.25C3 4.455 4.455 3 6.25 3h4C10.664 3 11 3.336 11 3.75S10.664 4.5 10.25 4.5h-4zM13 3.75C13 3.336 13.335 3 13.75 3h6.5C20.664 3 21 3.336 21 3.75v6.5c0 0.414-0.336 0.75-0.75 0.75s-0.75-0.336-0.75-0.75V5.56l-5.22 5.22c-0.293 0.293-0.768 0.293-1.06 0-0.293-0.293-0.293-0.768 0-1.06l5.22-5.22h-4.69C13.335 4.5 13 4.164 13 3.75z" android:fillColor="@color/fluent_default_icon_tint"/>
|
||||||
|
</vector>
|
|
@ -0,0 +1,3 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
|
||||||
|
<path android:pathData="M8.502 11.5c0.554 0 1.002 0.448 1.002 1.002 0 0.553-0.448 1.002-1.002 1.002-0.553 0-1.002-0.449-1.002-1.002 0-0.554 0.449-1.003 1.002-1.003zM12 4.353v6.651h7.442L17.72 9.28c-0.267-0.266-0.29-0.683-0.073-0.977L17.72 8.22c0.266-0.266 0.683-0.29 0.976-0.072L18.78 8.22l2.997 2.998c0.266 0.266 0.29 0.682 0.073 0.976l-0.073 0.084-2.996 3.003c-0.293 0.294-0.767 0.294-1.06 0.002-0.267-0.266-0.292-0.683-0.075-0.977l0.073-0.084 1.713-1.717h-7.431L12 19.25c0 0.466-0.421 0.82-0.88 0.738l-8.5-1.501C2.26 18.424 2 18.112 2 17.748V5.75c0-0.368 0.266-0.681 0.628-0.74l8.5-1.396C11.585 3.539 12 3.89 12 4.354zm-1.5 0.883l-7 1.15v10.732l7 1.236V5.237zM13 18.5h0.765l0.102-0.007c0.366-0.05 0.649-0.364 0.648-0.744l-0.007-4.25H13v5zm0.002-8.502L13 8.726V5h0.745c0.38 0 0.693 0.281 0.743 0.647l0.007 0.101L14.502 10h-1.5z" android:fillColor="@color/fluent_default_icon_tint"/>
|
||||||
|
</vector>
|
|
@ -0,0 +1,3 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
|
||||||
|
<path android:pathData="M14.704 3.44C14.895 3.667 15 3.953 15 4.248V19.75c0 0.69-0.56 1.25-1.25 1.25-0.296 0-0.582-0.105-0.808-0.296l-4.967-4.206H4.25c-1.243 0-2.25-1.008-2.25-2.25v-4.5c0-1.243 1.007-2.25 2.25-2.25h3.725l4.968-4.204c0.526-0.446 1.315-0.38 1.761 0.147zM13.5 4.787l-4.975 4.21H4.25c-0.414 0-0.75 0.337-0.75 0.75v4.5c0 0.415 0.336 0.75 0.75 0.75h4.275L13.5 19.21V4.787z" android:fillColor="@color/fluent_default_icon_tint"/>
|
||||||
|
</vector>
|
|
@ -0,0 +1,3 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="28dp" android:height="28dp" android:viewportWidth="28" android:viewportHeight="28">
|
||||||
|
<path android:pathData="M16.5 4.814c0-1.094-1.307-1.66-2.105-0.912l-4.937 4.63C9.134 8.836 8.706 9.005 8.261 9.005H5.25C3.455 9.005 2 10.46 2 12.255v3.492c0 1.795 1.455 3.25 3.25 3.25h3.012c0.444 0 0.872 0.17 1.196 0.473l4.937 4.626c0.799 0.748 2.105 0.182 2.105-0.912V4.814zm-6.016 4.812L15 5.39v17.216l-4.516-4.232c-0.602-0.564-1.397-0.878-2.222-0.878H5.25c-0.966 0-1.75-0.784-1.75-1.75v-3.492c0-0.966 0.784-1.75 1.75-1.75h3.011c0.826 0 1.62-0.314 2.223-0.88z" android:fillColor="@color/fluent_default_icon_tint"/>
|
||||||
|
</vector>
|
|
@ -0,0 +1,3 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
|
||||||
|
<path android:pathData="M3.28 2.22c-0.293-0.293-0.767-0.293-1.06 0-0.293 0.293-0.293 0.767 0 1.06L6.438 7.5H4.25C3.007 7.499 2 8.506 2 9.749v4.497c0 1.243 1.007 2.25 2.25 2.25h3.68c0.183 0 0.36 0.068 0.498 0.19l4.491 3.994C13.725 21.396 15 20.824 15 19.746V16.06l5.72 5.72c0.292 0.292 0.767 0.292 1.06 0 0.293-0.293 0.293-0.768 0-1.061L3.28 2.22zM13.5 14.56v4.629l-4.075-3.624c-0.412-0.366-0.944-0.569-1.495-0.569H4.25c-0.414 0-0.75-0.335-0.75-0.75V9.75C3.5 9.335 3.836 9 4.25 9h3.688l5.562 5.56zm0-9.753v5.511l1.5 1.5V4.25c0-1.079-1.274-1.65-2.08-0.934l-3.4 3.022 1.063 1.063L13.5 4.807zm3.641 9.152l1.138 1.138C18.741 14.163 19 13.111 19 12c0-1.203-0.304-2.338-0.84-3.328-0.198-0.364-0.653-0.5-1.017-0.303-0.364 0.197-0.5 0.653-0.303 1.017 0.42 0.777 0.66 1.666 0.66 2.614 0 0.691-0.127 1.351-0.359 1.96zm2.247 2.247l1.093 1.094C21.445 15.763 22 13.946 22 12c0-2.226-0.728-4.284-1.96-5.946-0.246-0.333-0.716-0.403-1.048-0.157-0.333 0.247-0.403 0.716-0.157 1.05C19.881 8.358 20.5 10.106 20.5 12c0 1.531-0.404 2.966-1.112 4.206z" android:fillColor="@color/fluent_default_icon_tint"/>
|
||||||
|
</vector>
|
|
@ -0,0 +1,3 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="28dp" android:height="28dp" android:viewportWidth="28" android:viewportHeight="28">
|
||||||
|
<path android:pathData="M3.28 2.22c-0.293-0.293-0.767-0.293-1.06 0-0.293 0.293-0.293 0.767 0 1.06l5.724 5.725H5.25C3.455 9.005 2 10.46 2 12.255v3.492c0 1.795 1.455 3.25 3.25 3.25h3.012c0.444 0 0.872 0.17 1.196 0.473l4.937 4.626c0.799 0.748 2.105 0.182 2.105-0.912v-5.623l8.22 8.22c0.292 0.292 0.767 0.292 1.06 0 0.293-0.293 0.293-0.768 0-1.061L3.28 2.22zM15 16.06v6.547l-4.516-4.231c-0.602-0.565-1.397-0.879-2.222-0.879H5.25c-0.966 0-1.75-0.783-1.75-1.75v-3.492c0-0.966 0.784-1.75 1.75-1.75h3.011c0.35 0 0.693-0.056 1.02-0.164L15 16.061zm-4.378-8.62l1.061 1.061L15 5.392v6.427l1.5 1.5V4.814c0-1.094-1.307-1.66-2.105-0.912L10.622 7.44zm9.55 9.55l1.137 1.137C21.912 16.88 22.25 15.478 22.25 14c0-2.136-0.706-4.11-1.897-5.697-0.249-0.332-0.719-0.399-1.05-0.15-0.332 0.249-0.399 0.719-0.15 1.05C20.156 10.54 20.75 12.199 20.75 14c0 1.058-0.205 2.067-0.578 2.99zm2.803 2.803l1.095 1.096c1.224-2.008 1.93-4.366 1.93-6.89 0-3.35-1.245-6.414-3.298-8.747-0.274-0.31-0.747-0.341-1.058-0.068-0.311 0.274-0.342 0.748-0.068 1.059C23.396 8.313 24.5 11.027 24.5 14c0 2.107-0.554 4.084-1.525 5.793z" android:fillColor="@color/fluent_default_icon_tint"/>
|
||||||
|
</vector>
|
|
@ -0,0 +1,20 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="108dp"
|
||||||
|
android:height="108dp"
|
||||||
|
android:viewportWidth="108"
|
||||||
|
android:viewportHeight="108">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FF000000"
|
||||||
|
android:pathData="M54,90L54,90c-19.9,0 -36,-16.1 -36,-36v0c0,-19.9 16.1,-36 36,-36h0c19.9,0 36,16.1 36,36v0C90,73.9 73.9,90 54,90z"
|
||||||
|
android:strokeAlpha="0"
|
||||||
|
android:fillAlpha="0"/>
|
||||||
|
<path
|
||||||
|
android:pathData="M52.5,41.6c-2.4,0 -4.3,0.9 -5.5,2.8l-1.2,2l-1.2,-2c-1.2,-1.9 -3.1,-2.8 -5.5,-2.8c-2.1,0 -3.8,0.8 -5.1,2.2c-1.2,1.4 -1.9,3.4 -1.9,5.9v12h4.7V50c0,-2.4 1.1,-3.7 3.1,-3.7c2.3,0 3.4,1.4 3.4,4.4v6.4h4.7v-6.4c0,-2.9 1.1,-4.4 3.4,-4.4c2.1,0 3.1,1.2 3.1,3.7v11.7h4.7v-12c0,-2.4 -0.6,-4.4 -1.9,-5.9C56.2,42.3 54.6,41.6 52.5,41.6z"
|
||||||
|
android:fillColor="#33D17A"/>
|
||||||
|
<path
|
||||||
|
android:pathData="M65.9,58.1h0.8c0,0 0,0 -0.1,0c-0.6,-0.3 -1.1,-0.8 -1.4,-1.4c-0.3,-0.6 -0.5,-1.4 -0.5,-2.1c0,-0.8 0.2,-1.5 0.5,-2.1c0.4,-0.6 0.8,-1.1 1.4,-1.4c0.6,-0.3 1.2,-0.5 1.9,-0.5c0.7,0 1.3,0.2 1.9,0.5s1.1,0.8 1.4,1.4s0.5,1.3 0.5,2.1c0,0.2 0,0.4 0,0.6l0.7,0.7c0.4,0 0.8,0 1.1,0l1.5,-1.5l0.2,-0.2c-0.1,-1.2 -0.4,-2.3 -0.9,-3.4c-0.6,-1.1 -1.4,-2 -2.6,-2.6c-1.1,-0.6 -2.4,-1 -3.7,-1c-1.4,0 -2.7,0.3 -3.8,1c-1.1,0.6 -2,1.5 -2.6,2.6c-0.6,1.1 -0.9,2.4 -0.9,3.7s0.3,2.7 0.9,3.7c0.6,1.1 1.5,2 2.6,2.6c0.4,0.2 0.8,0.4 1.1,0.5v-1.8V58.1z"
|
||||||
|
android:fillColor="#33D17A"/>
|
||||||
|
<path
|
||||||
|
android:pathData="M76,58.3l1.2,-1.2L76.2,56l-1.7,1.7c-0.4,-0.1 -0.7,-0.2 -1.1,-0.2s-0.8,0.1 -1.1,0.2L70.7,56l-1,1.1l1.2,1.2c-0.5,0.4 -1.1,0.9 -1.4,1.5h-2.1v1.5H69c0,0.2 -0.1,0.5 -0.1,0.8v0.8h-1.5v1.5h1.5v0.8c0,0.2 0,0.5 0.1,0.8h-1.6v1.5h2.1c0.8,1.4 2.3,2.3 4,2.3s3.1,-0.9 4,-2.3h2.1v-1.5H78c0,-0.2 0.1,-0.5 0.1,-0.8v-0.8h1.5v-1.5h-1.5v-0.8c0,-0.2 0,-0.5 -0.1,-0.8h1.6v-1.5h-2.1C77.1,59.2 76.6,58.8 76,58.3zM75,65.9H72v-1.5H75V65.9zM75,62.9H72v-1.5H75V62.9z"
|
||||||
|
android:fillColor="#33D17A"/>
|
||||||
|
</vector>
|
|
@ -0,0 +1,20 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="108dp"
|
||||||
|
android:height="108dp"
|
||||||
|
android:viewportWidth="108"
|
||||||
|
android:viewportHeight="108">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FF000000"
|
||||||
|
android:pathData="M54,90L54,90c-19.9,0 -36,-16.1 -36,-36v0c0,-19.9 16.1,-36 36,-36h0c19.9,0 36,16.1 36,36v0C90,73.9 73.9,90 54,90z"
|
||||||
|
android:strokeAlpha="0"
|
||||||
|
android:fillAlpha="0"/>
|
||||||
|
<path
|
||||||
|
android:pathData="M52.5,41.6c-2.4,0 -4.3,0.9 -5.5,2.8l-1.2,2l-1.2,-2c-1.2,-1.9 -3.1,-2.8 -5.5,-2.8c-2.1,0 -3.8,0.8 -5.1,2.2c-1.2,1.4 -1.9,3.4 -1.9,5.9v12h4.7V50c0,-2.4 1.1,-3.7 3.1,-3.7c2.3,0 3.4,1.4 3.4,4.4v6.4h4.7v-6.4c0,-2.9 1.1,-4.4 3.4,-4.4c2.1,0 3.1,1.2 3.1,3.7v11.7h4.7v-12c0,-2.4 -0.6,-4.4 -1.9,-5.9C56.2,42.3 54.6,41.6 52.5,41.6z"
|
||||||
|
android:fillColor="#33D17A"/>
|
||||||
|
<path
|
||||||
|
android:pathData="M65.9,58.1h0.8c0,0 0,0 -0.1,0c-0.6,-0.3 -1.1,-0.8 -1.4,-1.4c-0.3,-0.6 -0.5,-1.4 -0.5,-2.1c0,-0.8 0.2,-1.5 0.5,-2.1c0.4,-0.6 0.8,-1.1 1.4,-1.4c0.6,-0.3 1.2,-0.5 1.9,-0.5c0.7,0 1.3,0.2 1.9,0.5s1.1,0.8 1.4,1.4s0.5,1.3 0.5,2.1c0,0.2 0,0.4 0,0.6l0.7,0.7c0.4,0 0.8,0 1.1,0l1.5,-1.5l0.2,-0.2c-0.1,-1.2 -0.4,-2.3 -0.9,-3.4c-0.6,-1.1 -1.4,-2 -2.6,-2.6c-1.1,-0.6 -2.4,-1 -3.7,-1c-1.4,0 -2.7,0.3 -3.8,1c-1.1,0.6 -2,1.5 -2.6,2.6c-0.6,1.1 -0.9,2.4 -0.9,3.7s0.3,2.7 0.9,3.7c0.6,1.1 1.5,2 2.6,2.6c0.4,0.2 0.8,0.4 1.1,0.5v-1.8V58.1z"
|
||||||
|
android:fillColor="#33D17A"/>
|
||||||
|
<path
|
||||||
|
android:pathData="M76,58.3l1.2,-1.2L76.2,56l-1.7,1.7c-0.4,-0.1 -0.7,-0.2 -1.1,-0.2s-0.8,0.1 -1.1,0.2L70.7,56l-1,1.1l1.2,1.2c-0.5,0.4 -1.1,0.9 -1.4,1.5h-2.1v1.5H69c0,0.2 -0.1,0.5 -0.1,0.8v0.8h-1.5v1.5h1.5v0.8c0,0.2 0,0.5 0.1,0.8h-1.6v1.5h2.1c0.8,1.4 2.3,2.3 4,2.3s3.1,-0.9 4,-2.3h2.1v-1.5H78c0,-0.2 0.1,-0.5 0.1,-0.8v-0.8h1.5v-1.5h-1.5v-0.8c0,-0.2 0,-0.5 -0.1,-0.8h1.6v-1.5h-2.1C77.1,59.2 76.6,58.8 76,58.3zM75,65.9H72v-1.5H75V65.9zM75,62.9H72v-1.5H75V62.9z"
|
||||||
|
android:fillColor="#33D17A"/>
|
||||||
|
</vector>
|
6
mastodon/src/debug/res/mipmap-anydpi-v26/ic_launcher.xml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<background android:drawable="@color/ic_launcher_background"/>
|
||||||
|
<foreground android:drawable="@drawable/ic_launcher_foreground_debug"/>
|
||||||
|
<monochrome android:drawable="@drawable/ic_launcher_foreground_monochrome_debug"/>
|
||||||
|
</adaptive-icon>
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<background android:drawable="@color/ic_launcher_background"/>
|
||||||
|
<foreground android:drawable="@drawable/ic_launcher_foreground_debug"/>
|
||||||
|
<monochrome android:drawable="@drawable/ic_launcher_foreground_monochrome_debug"/>
|
||||||
|
</adaptive-icon>
|
BIN
mastodon/src/debug/res/mipmap-hdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
mastodon/src/debug/res/mipmap-hdpi/ic_launcher_round.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
mastodon/src/debug/res/mipmap-mdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 988 B |
BIN
mastodon/src/debug/res/mipmap-mdpi/ic_launcher_round.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
mastodon/src/debug/res/mipmap-xhdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
mastodon/src/debug/res/mipmap-xhdpi/ic_launcher_round.png
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
mastodon/src/debug/res/mipmap-xxhdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
mastodon/src/debug/res/mipmap-xxhdpi/ic_launcher_round.png
Normal file
After Width: | Height: | Size: 6.1 KiB |
BIN
mastodon/src/debug/res/mipmap-xxxhdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 3.9 KiB |
BIN
mastodon/src/debug/res/mipmap-xxxhdpi/ic_launcher_round.png
Normal file
After Width: | Height: | Size: 8.5 KiB |
4
mastodon/src/debug/res/values/ic_launcher_background.xml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<color name="ic_launcher_background">#000000</color>
|
||||||
|
</resources>
|
|
@ -115,7 +115,7 @@ public class GithubSelfUpdaterImpl extends GithubSelfUpdater{
|
||||||
|
|
||||||
private void actuallyCheckForUpdates(){
|
private void actuallyCheckForUpdates(){
|
||||||
Request req=new Request.Builder()
|
Request req=new Request.Builder()
|
||||||
.url("https://api.github.com/repos/sk22/megalodon/releases")
|
.url("https://api.github.com/repos/LucasGGamerM/moshidon/releases")
|
||||||
.build();
|
.build();
|
||||||
Call call=MastodonAPIController.getHttpClient().newCall(req);
|
Call call=MastodonAPIController.getHttpClient().newCall(req);
|
||||||
try(Response resp=call.execute()){
|
try(Response resp=call.execute()){
|
||||||
|
@ -154,7 +154,7 @@ public class GithubSelfUpdaterImpl extends GithubSelfUpdater{
|
||||||
Log.d(TAG, "actuallyCheckForUpdates: new version: "+version);
|
Log.d(TAG, "actuallyCheckForUpdates: new version: "+version);
|
||||||
for(JsonElement el:obj.getAsJsonArray("assets")){
|
for(JsonElement el:obj.getAsJsonArray("assets")){
|
||||||
JsonObject asset=el.getAsJsonObject();
|
JsonObject asset=el.getAsJsonObject();
|
||||||
if("megalodon.apk".equals(asset.get("name").getAsString()) && "application/vnd.android.package-archive".equals(asset.get("content_type").getAsString()) && "uploaded".equals(asset.get("state").getAsString())){
|
if("moshidon.apk".equals(asset.get("name").getAsString()) && "application/vnd.android.package-archive".equals(asset.get("content_type").getAsString()) && "uploaded".equals(asset.get("state").getAsString())){
|
||||||
long size=asset.get("size").getAsLong();
|
long size=asset.get("size").getAsLong();
|
||||||
String url=asset.get("browser_download_url").getAsString();
|
String url=asset.get("browser_download_url").getAsString();
|
||||||
|
|
||||||
|
@ -211,7 +211,13 @@ public class GithubSelfUpdaterImpl extends GithubSelfUpdater{
|
||||||
if(state==UpdateState.DOWNLOADING)
|
if(state==UpdateState.DOWNLOADING)
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
DownloadManager dm=MastodonApp.context.getSystemService(DownloadManager.class);
|
DownloadManager dm=MastodonApp.context.getSystemService(DownloadManager.class);
|
||||||
|
|
||||||
|
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.TIRAMISU){
|
||||||
|
MastodonApp.context.registerReceiver(downloadCompletionReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE), Context.RECEIVER_EXPORTED);
|
||||||
|
}else{
|
||||||
MastodonApp.context.registerReceiver(downloadCompletionReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
|
MastodonApp.context.registerReceiver(downloadCompletionReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
|
||||||
|
}
|
||||||
|
|
||||||
downloadID=dm.enqueue(
|
downloadID=dm.enqueue(
|
||||||
new DownloadManager.Request(Uri.parse(getPrefs().getString("apkURL", null)))
|
new DownloadManager.Request(Uri.parse(getPrefs().getString("apkURL", null)))
|
||||||
.setDestinationUri(Uri.fromFile(getUpdateApkFile()))
|
.setDestinationUri(Uri.fromFile(getUpdateApkFile()))
|
||||||
|
|
|
@ -1,16 +1,22 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:tools="http://schemas.android.com/tools"
|
<manifest xmlns:tools="http://schemas.android.com/tools"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="org.joinmastodon.android">
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET"/>
|
<uses-permission android:name="android.permission.INTERNET"/>
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
|
||||||
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK"/>
|
||||||
<uses-permission android:name="android.permission.VIBRATE" />
|
<uses-permission android:name="android.permission.VIBRATE" />
|
||||||
|
<uses-permission android:name="android.permission.CAMERA" />
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28"/>
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28"/>
|
||||||
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE"/>
|
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE"/>
|
||||||
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
|
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
|
||||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
|
||||||
|
|
||||||
<permission android:name="${applicationId}.permission.C2D_MESSAGE" android:protectionLevel="signature"/>
|
<permission android:name="${applicationId}.permission.C2D_MESSAGE" android:protectionLevel="signature"/>
|
||||||
|
<uses-feature
|
||||||
|
android:name="android.hardware.camera"
|
||||||
|
android:required="false" />
|
||||||
|
|
||||||
<queries>
|
<queries>
|
||||||
<intent>
|
<intent>
|
||||||
|
@ -25,11 +31,13 @@
|
||||||
<application
|
<application
|
||||||
android:name=".MastodonApp"
|
android:name=".MastodonApp"
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:label="@string/sk_app_name"
|
android:label="@string/mo_app_name"
|
||||||
|
android:dataExtractionRules="@xml/backup_rules"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:localeConfig="@xml/locales_config"
|
android:localeConfig="@xml/locales_config"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:theme="@style/Theme.Mastodon.AutoLightDark"
|
android:theme="@style/Theme.Mastodon.AutoLightDark"
|
||||||
|
android:windowSoftInputMode="adjustPan"
|
||||||
android:largeHeap="true">
|
android:largeHeap="true">
|
||||||
|
|
||||||
<activity android:name=".MainActivity" android:exported="true" android:configChanges="orientation|screenSize" android:windowSoftInputMode="adjustResize" android:launchMode="singleTask">
|
<activity android:name=".MainActivity" android:exported="true" android:configChanges="orientation|screenSize" android:windowSoftInputMode="adjustResize" android:launchMode="singleTask">
|
||||||
|
@ -58,7 +66,7 @@
|
||||||
<action android:name="android.intent.action.VIEW"/>
|
<action android:name="android.intent.action.VIEW"/>
|
||||||
<category android:name="android.intent.category.BROWSABLE"/>
|
<category android:name="android.intent.category.BROWSABLE"/>
|
||||||
<category android:name="android.intent.category.DEFAULT"/>
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
<data android:scheme="megalodon-android-auth" android:host="callback"/>
|
<data android:scheme="${oAuthScheme}" android:host="callback"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name=".ExternalShareActivity" android:exported="true" android:configChanges="orientation|screenSize" android:windowSoftInputMode="adjustResize"
|
<activity android:name=".ExternalShareActivity" android:exported="true" android:configChanges="orientation|screenSize" android:windowSoftInputMode="adjustResize"
|
||||||
|
@ -74,6 +82,15 @@
|
||||||
<data android:mimeType="*/*"/>
|
<data android:mimeType="*/*"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
<activity android:name=".ChooseAccountForComposeActivity" android:exported="true" android:configChanges="orientation|screenSize" android:windowSoftInputMode="adjustResize"
|
||||||
|
android:theme="@style/TransparentDialog">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.CHOOSER"/>
|
||||||
|
<category android:name="android.intent.category.LAUNCHER"/>
|
||||||
|
<data android:mimeType="*/*"/>
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
|
|
||||||
<service android:name=".AudioPlayerService" android:foregroundServiceType="mediaPlayback"/>
|
<service android:name=".AudioPlayerService" android:foregroundServiceType="mediaPlayback"/>
|
||||||
|
|
||||||
|
@ -98,6 +115,14 @@
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
|
<provider
|
||||||
|
android:authorities="${applicationId}.fileprovider"
|
||||||
|
android:name=".TweakedFileProvider"
|
||||||
|
android:grantUriPermissions="true"
|
||||||
|
android:exported="false">
|
||||||
|
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/fileprovider_paths"/>
|
||||||
|
</provider>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
|
@ -20,13 +20,16 @@ cachapa.xyz
|
||||||
canary.fedinuke.example.com
|
canary.fedinuke.example.com
|
||||||
catgirl.life
|
catgirl.life
|
||||||
cawfee.club
|
cawfee.club
|
||||||
childlove.space
|
childlove.su
|
||||||
clew.lol
|
clew.lol
|
||||||
clubcyberia.co
|
clubcyberia.co
|
||||||
contrapointsfan.club
|
contrapointsfan.club
|
||||||
|
cottoncandy.cafe
|
||||||
|
crlf.ninja
|
||||||
crucible.world
|
crucible.world
|
||||||
cum.camp
|
cum.camp
|
||||||
cum.salon
|
cum.salon
|
||||||
|
cunnyborea.space
|
||||||
decayable.ink
|
decayable.ink
|
||||||
dembased.xyz
|
dembased.xyz
|
||||||
detroitriotcity.com
|
detroitriotcity.com
|
||||||
|
@ -34,10 +37,12 @@ djsumdog.com
|
||||||
eientei.org
|
eientei.org
|
||||||
eveningzoo.club
|
eveningzoo.club
|
||||||
fluf.club
|
fluf.club
|
||||||
|
foxgirl.lol
|
||||||
freak.university
|
freak.university
|
||||||
freeatlantis.com
|
freeatlantis.com
|
||||||
freespeechextremist.com
|
freespeechextremist.com
|
||||||
froth.zone
|
froth.zone
|
||||||
|
fsebugoutzone.org
|
||||||
gameliberty.club
|
gameliberty.club
|
||||||
gearlandia.haus
|
gearlandia.haus
|
||||||
genderheretics.xyz
|
genderheretics.xyz
|
||||||
|
@ -49,6 +54,7 @@ goyim.app
|
||||||
h5q.net
|
h5q.net
|
||||||
haeder.net
|
haeder.net
|
||||||
handholding.io
|
handholding.io
|
||||||
|
harpy.faith
|
||||||
hitchhiker.social
|
hitchhiker.social
|
||||||
iddqd.social
|
iddqd.social
|
||||||
kitsunemimi.club
|
kitsunemimi.club
|
||||||
|
@ -56,15 +62,14 @@ kiwifarms.cc
|
||||||
kurosawa.moe
|
kurosawa.moe
|
||||||
kyaruc.moe
|
kyaruc.moe
|
||||||
leafposter.club
|
leafposter.club
|
||||||
lewdieheaven.com
|
|
||||||
liberdon.com
|
liberdon.com
|
||||||
ligma.pro
|
ligma.pro
|
||||||
|
loli.church
|
||||||
lolicon.rocks
|
lolicon.rocks
|
||||||
lolison.network
|
lolison.network
|
||||||
lolison.top
|
lolison.top
|
||||||
lovingexpressions.net
|
lovingexpressions.net
|
||||||
makemysarcophagus.com
|
makemysarcophagus.com
|
||||||
marsey.moe
|
|
||||||
mastinator.com
|
mastinator.com
|
||||||
merovingian.club
|
merovingian.club
|
||||||
midwaytrades.com
|
midwaytrades.com
|
||||||
|
@ -74,17 +79,21 @@ mouse.services
|
||||||
mugicha.club
|
mugicha.club
|
||||||
narrativerry.xyz
|
narrativerry.xyz
|
||||||
natehiggers.online
|
natehiggers.online
|
||||||
|
nationalist.social
|
||||||
needs.vodka
|
needs.vodka
|
||||||
neenster.org
|
neenster.org
|
||||||
nicecrew.digital
|
nicecrew.digital
|
||||||
|
nightshift.social
|
||||||
nnia.space
|
nnia.space
|
||||||
noagendasocial.com
|
noagendasocial.com
|
||||||
noagendasocial.nl
|
noagendasocial.nl
|
||||||
noagendatube.com
|
noagendatube.com
|
||||||
|
noauthority.social
|
||||||
nobodyhasthe.biz
|
nobodyhasthe.biz
|
||||||
norwoodzero.net
|
norwoodzero.net
|
||||||
nyanide.com
|
nyanide.com
|
||||||
onionfarms.org
|
onionfarms.org
|
||||||
|
parcero.bond
|
||||||
pawlicker.com
|
pawlicker.com
|
||||||
pawoo.net
|
pawoo.net
|
||||||
pedo.school
|
pedo.school
|
||||||
|
@ -129,9 +138,11 @@ sonichu.com
|
||||||
spinster.xyz
|
spinster.xyz
|
||||||
springbo.cc
|
springbo.cc
|
||||||
strelizia.net
|
strelizia.net
|
||||||
|
taihou.website
|
||||||
tastingtraffic.net
|
tastingtraffic.net
|
||||||
teci.world
|
teci.world
|
||||||
theapex.social
|
theapex.social
|
||||||
|
theblab.org
|
||||||
thechimp.zone
|
thechimp.zone
|
||||||
thenobody.club
|
thenobody.club
|
||||||
thepostearthdestination.com
|
thepostearthdestination.com
|
||||||
|
@ -139,9 +150,11 @@ tkammer.de
|
||||||
trumpislovetrumpis.life
|
trumpislovetrumpis.life
|
||||||
truthsocial.co.in
|
truthsocial.co.in
|
||||||
usualsuspects.lol
|
usualsuspects.lol
|
||||||
|
vampiremaid.cafe
|
||||||
varishangout.net
|
varishangout.net
|
||||||
vtuberfan.social
|
vtuberfan.social
|
||||||
wolfgirl.bar
|
wolfgirl.bar
|
||||||
xn--p1abe3d.xn--80asehdb
|
xn--p1abe3d.xn--80asehdb
|
||||||
yggdrasil.social
|
yggdrasil.social
|
||||||
youjo.love
|
youjo.love
|
||||||
|
zhub.link
|
Before Width: | Height: | Size: 358 KiB After Width: | Height: | Size: 11 KiB |
|
@ -88,8 +88,13 @@ public class AudioPlayerService extends Service{
|
||||||
nm=getSystemService(NotificationManager.class);
|
nm=getSystemService(NotificationManager.class);
|
||||||
// registerReceiver(receiver, new IntentFilter(Intent.ACTION_MEDIA_BUTTON));
|
// registerReceiver(receiver, new IntentFilter(Intent.ACTION_MEDIA_BUTTON));
|
||||||
registerReceiver(receiver, new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY));
|
registerReceiver(receiver, new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY));
|
||||||
|
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.TIRAMISU){
|
||||||
|
registerReceiver(receiver, new IntentFilter(ACTION_PLAY_PAUSE), RECEIVER_EXPORTED);
|
||||||
|
registerReceiver(receiver, new IntentFilter(ACTION_STOP), RECEIVER_EXPORTED);
|
||||||
|
}else{
|
||||||
registerReceiver(receiver, new IntentFilter(ACTION_PLAY_PAUSE));
|
registerReceiver(receiver, new IntentFilter(ACTION_PLAY_PAUSE));
|
||||||
registerReceiver(receiver, new IntentFilter(ACTION_STOP));
|
registerReceiver(receiver, new IntentFilter(ACTION_STOP));
|
||||||
|
}
|
||||||
instance=this;
|
instance=this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
package org.joinmastodon.android;
|
||||||
|
|
||||||
|
import android.app.Fragment;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import org.joinmastodon.android.api.session.AccountSession;
|
||||||
|
import org.joinmastodon.android.api.session.AccountSessionManager;
|
||||||
|
import org.joinmastodon.android.fragments.ComposeFragment;
|
||||||
|
import org.joinmastodon.android.ui.sheets.AccountSwitcherSheet;
|
||||||
|
import org.joinmastodon.android.ui.utils.UiUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import me.grishka.appkit.FragmentStackActivity;
|
||||||
|
|
||||||
|
public class ChooseAccountForComposeActivity extends FragmentStackActivity{
|
||||||
|
@Override
|
||||||
|
protected void onCreate(@Nullable Bundle savedInstanceState){
|
||||||
|
UiUtils.setUserPreferredTheme(this);
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
if (savedInstanceState == null && Objects.equals(getIntent().getAction(), Intent.ACTION_CHOOSER)) {
|
||||||
|
AccountSessionManager.getInstance().maybeUpdateLocalInfo();
|
||||||
|
List<AccountSession> sessions=AccountSessionManager.getInstance().getLoggedInAccounts();
|
||||||
|
if (sessions.isEmpty()){
|
||||||
|
Toast.makeText(this, R.string.err_not_logged_in, Toast.LENGTH_SHORT).show();
|
||||||
|
finish();
|
||||||
|
} else if (sessions.size() > 1) {
|
||||||
|
AccountSwitcherSheet sheet = new AccountSwitcherSheet(this, null, R.drawable.ic_fluent_compose_28_regular,
|
||||||
|
R.string.choose_account, null, false);
|
||||||
|
sheet.setOnClick((accountId, open) -> {
|
||||||
|
openComposeFragment(accountId);
|
||||||
|
});
|
||||||
|
sheet.show();
|
||||||
|
} else if (sessions.size() == 1) {
|
||||||
|
openComposeFragment(sessions.get(0).getID());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void openComposeFragment(String accountID){
|
||||||
|
getWindow().setBackgroundDrawable(null);
|
||||||
|
Bundle args=new Bundle();
|
||||||
|
args.putString("account", accountID);
|
||||||
|
Fragment fragment=new ComposeFragment();
|
||||||
|
fragment.setArguments(args);
|
||||||
|
showFragmentClearingBackStack(fragment);
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,7 +13,7 @@ import org.joinmastodon.android.api.MastodonAPIRequest;
|
||||||
import org.joinmastodon.android.api.session.AccountSession;
|
import org.joinmastodon.android.api.session.AccountSession;
|
||||||
import org.joinmastodon.android.api.session.AccountSessionManager;
|
import org.joinmastodon.android.api.session.AccountSessionManager;
|
||||||
import org.joinmastodon.android.fragments.ComposeFragment;
|
import org.joinmastodon.android.fragments.ComposeFragment;
|
||||||
import org.joinmastodon.android.ui.AccountSwitcherSheet;
|
import org.joinmastodon.android.ui.sheets.AccountSwitcherSheet;
|
||||||
import org.joinmastodon.android.ui.utils.UiUtils;
|
import org.joinmastodon.android.ui.utils.UiUtils;
|
||||||
import org.jsoup.internal.StringUtil;
|
import org.jsoup.internal.StringUtil;
|
||||||
|
|
||||||
|
@ -42,7 +42,11 @@ public class ExternalShareActivity extends FragmentStackActivity{
|
||||||
Toast.makeText(this, R.string.err_not_logged_in, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.err_not_logged_in, Toast.LENGTH_SHORT).show();
|
||||||
finish();
|
finish();
|
||||||
} else if (isOpenable || sessions.size() > 1) {
|
} else if (isOpenable || sessions.size() > 1) {
|
||||||
AccountSwitcherSheet sheet = new AccountSwitcherSheet(this, null, true, isOpenable);
|
AccountSwitcherSheet sheet = new AccountSwitcherSheet(this, null, R.drawable.ic_fluent_share_28_regular,
|
||||||
|
isOpenable
|
||||||
|
? R.string.sk_external_share_or_open_title
|
||||||
|
: R.string.sk_external_share_title,
|
||||||
|
null, isOpenable);
|
||||||
sheet.setOnClick((accountId, open) -> {
|
sheet.setOnClick((accountId, open) -> {
|
||||||
if (open && text.isPresent()) {
|
if (open && text.isPresent()) {
|
||||||
BiConsumer<Class<? extends Fragment>, Bundle> callback = (clazz, args) -> {
|
BiConsumer<Class<? extends Fragment>, Bundle> callback = (clazz, args) -> {
|
||||||
|
@ -82,6 +86,8 @@ public class ExternalShareActivity extends FragmentStackActivity{
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openComposeFragment(String accountID){
|
private void openComposeFragment(String accountID){
|
||||||
|
AccountSession session=AccountSessionManager.get(accountID);
|
||||||
|
UiUtils.setUserPreferredTheme(this, session);
|
||||||
getWindow().setBackgroundDrawable(null);
|
getWindow().setBackgroundDrawable(null);
|
||||||
|
|
||||||
Intent intent=getIntent();
|
Intent intent=getIntent();
|
||||||
|
|
|
@ -0,0 +1,841 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.joinmastodon.android;
|
||||||
|
|
||||||
|
import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT;
|
||||||
|
import static org.xmlpull.v1.XmlPullParser.START_TAG;
|
||||||
|
|
||||||
|
import android.content.ClipData;
|
||||||
|
import android.content.ContentProvider;
|
||||||
|
import android.content.ContentValues;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.pm.ProviderInfo;
|
||||||
|
import android.content.res.XmlResourceParser;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.database.MatrixCursor;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Environment;
|
||||||
|
import android.os.ParcelFileDescriptor;
|
||||||
|
import android.provider.OpenableColumns;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.webkit.MimeTypeMap;
|
||||||
|
|
||||||
|
import androidx.annotation.GuardedBy;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FileProvider is a special subclass of {@link ContentProvider} that facilitates secure sharing
|
||||||
|
* of files associated with an app by creating a <code>content://</code> {@link Uri} for a file
|
||||||
|
* instead of a <code>file:///</code> {@link Uri}.
|
||||||
|
* <p>
|
||||||
|
* A content URI allows you to grant read and write access using
|
||||||
|
* temporary access permissions. When you create an {@link Intent} containing
|
||||||
|
* a content URI, in order to send the content URI
|
||||||
|
* to a client app, you can also call {@link Intent#setFlags(int) Intent.setFlags()} to add
|
||||||
|
* permissions. These permissions are available to the client app for as long as the stack for
|
||||||
|
* a receiving {@link android.app.Activity} is active. For an {@link Intent} going to a
|
||||||
|
* {@link android.app.Service}, the permissions are available as long as the
|
||||||
|
* {@link android.app.Service} is running.
|
||||||
|
* <p>
|
||||||
|
* In comparison, to control access to a <code>file:///</code> {@link Uri} you have to modify the
|
||||||
|
* file system permissions of the underlying file. The permissions you provide become available to
|
||||||
|
* <em>any</em> app, and remain in effect until you change them. This level of access is
|
||||||
|
* fundamentally insecure.
|
||||||
|
* <p>
|
||||||
|
* The increased level of file access security offered by a content URI
|
||||||
|
* makes FileProvider a key part of Android's security infrastructure.
|
||||||
|
* <p>
|
||||||
|
* This overview of FileProvider includes the following topics:
|
||||||
|
* </p>
|
||||||
|
* <ol>
|
||||||
|
* <li><a href="#ProviderDefinition">Defining a FileProvider</a></li>
|
||||||
|
* <li><a href="#SpecifyFiles">Specifying Available Files</a></li>
|
||||||
|
* <li><a href="#GetUri">Retrieving the Content URI for a File</li>
|
||||||
|
* <li><a href="#Permissions">Granting Temporary Permissions to a URI</a></li>
|
||||||
|
* <li><a href="#ServeUri">Serving a Content URI to Another App</a></li>
|
||||||
|
* </ol>
|
||||||
|
* <h3 id="ProviderDefinition">Defining a FileProvider</h3>
|
||||||
|
* <p>
|
||||||
|
* Since the default functionality of FileProvider includes content URI generation for files, you
|
||||||
|
* don't need to define a subclass in code. Instead, you can include a FileProvider in your app
|
||||||
|
* by specifying it entirely in XML. To specify the FileProvider component itself, add a
|
||||||
|
* <code><a href="{@docRoot}guide/topics/manifest/provider-element.html"><provider></a></code>
|
||||||
|
* element to your app manifest. Set the <code>android:name</code> attribute to
|
||||||
|
* <code>androidx.core.content.FileProvider</code>. Set the <code>android:authorities</code>
|
||||||
|
* attribute to a URI authority based on a domain you control; for example, if you control the
|
||||||
|
* domain <code>mydomain.com</code> you should use the authority
|
||||||
|
* <code>com.mydomain.fileprovider</code>. Set the <code>android:exported</code> attribute to
|
||||||
|
* <code>false</code>; the FileProvider does not need to be public. Set the
|
||||||
|
* <a href="{@docRoot}guide/topics/manifest/provider-element.html#gprmsn"
|
||||||
|
* >android:grantUriPermissions</a> attribute to <code>true</code>, to allow you
|
||||||
|
* to grant temporary access to files. For example:
|
||||||
|
* <pre class="prettyprint">
|
||||||
|
*<manifest>
|
||||||
|
* ...
|
||||||
|
* <application>
|
||||||
|
* ...
|
||||||
|
* <provider
|
||||||
|
* android:name="androidx.core.content.FileProvider"
|
||||||
|
* android:authorities="com.mydomain.fileprovider"
|
||||||
|
* android:exported="false"
|
||||||
|
* android:grantUriPermissions="true">
|
||||||
|
* ...
|
||||||
|
* </provider>
|
||||||
|
* ...
|
||||||
|
* </application>
|
||||||
|
*</manifest></pre>
|
||||||
|
* <p>
|
||||||
|
* If you want to override any of the default behavior of FileProvider methods, extend
|
||||||
|
* the FileProvider class and use the fully-qualified class name in the <code>android:name</code>
|
||||||
|
* attribute of the <code><provider></code> element.
|
||||||
|
* <h3 id="SpecifyFiles">Specifying Available Files</h3>
|
||||||
|
* A FileProvider can only generate a content URI for files in directories that you specify
|
||||||
|
* beforehand. To specify a directory, specify the its storage area and path in XML, using child
|
||||||
|
* elements of the <code><paths></code> element.
|
||||||
|
* For example, the following <code>paths</code> element tells FileProvider that you intend to
|
||||||
|
* request content URIs for the <code>images/</code> subdirectory of your private file area.
|
||||||
|
* <pre class="prettyprint">
|
||||||
|
*<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
* <files-path name="my_images" path="images/"/>
|
||||||
|
* ...
|
||||||
|
*</paths>
|
||||||
|
*</pre>
|
||||||
|
* <p>
|
||||||
|
* The <code><paths></code> element must contain one or more of the following child elements:
|
||||||
|
* </p>
|
||||||
|
* <dl>
|
||||||
|
* <dt>
|
||||||
|
* <pre class="prettyprint">
|
||||||
|
*<files-path name="<i>name</i>" path="<i>path</i>" />
|
||||||
|
*</pre>
|
||||||
|
* </dt>
|
||||||
|
* <dd>
|
||||||
|
* Represents files in the <code>files/</code> subdirectory of your app's internal storage
|
||||||
|
* area. This subdirectory is the same as the value returned by {@link Context#getFilesDir()
|
||||||
|
* Context.getFilesDir()}.
|
||||||
|
* </dd>
|
||||||
|
* <dt>
|
||||||
|
* <pre>
|
||||||
|
*<cache-path name="<i>name</i>" path="<i>path</i>" />
|
||||||
|
*</pre>
|
||||||
|
* <dt>
|
||||||
|
* <dd>
|
||||||
|
* Represents files in the cache subdirectory of your app's internal storage area. The root path
|
||||||
|
* of this subdirectory is the same as the value returned by {@link Context#getCacheDir()
|
||||||
|
* getCacheDir()}.
|
||||||
|
* </dd>
|
||||||
|
* <dt>
|
||||||
|
* <pre class="prettyprint">
|
||||||
|
*<external-path name="<i>name</i>" path="<i>path</i>" />
|
||||||
|
*</pre>
|
||||||
|
* </dt>
|
||||||
|
* <dd>
|
||||||
|
* Represents files in the root of the external storage area. The root path of this subdirectory
|
||||||
|
* is the same as the value returned by
|
||||||
|
* {@link Environment#getExternalStorageDirectory() Environment.getExternalStorageDirectory()}.
|
||||||
|
* </dd>
|
||||||
|
* <dt>
|
||||||
|
* <pre class="prettyprint">
|
||||||
|
*<external-files-path name="<i>name</i>" path="<i>path</i>" />
|
||||||
|
*</pre>
|
||||||
|
* </dt>
|
||||||
|
* <dd>
|
||||||
|
* Represents files in the root of your app's external storage area. The root path of this
|
||||||
|
* subdirectory is the same as the value returned by
|
||||||
|
* {@code Context#getExternalFilesDir(String) Context.getExternalFilesDir(null)}.
|
||||||
|
* </dd>
|
||||||
|
* <dt>
|
||||||
|
* <pre class="prettyprint">
|
||||||
|
*<external-cache-path name="<i>name</i>" path="<i>path</i>" />
|
||||||
|
*</pre>
|
||||||
|
* </dt>
|
||||||
|
* <dd>
|
||||||
|
* Represents files in the root of your app's external cache area. The root path of this
|
||||||
|
* subdirectory is the same as the value returned by
|
||||||
|
* {@link Context#getExternalCacheDir() Context.getExternalCacheDir()}.
|
||||||
|
* </dd>
|
||||||
|
* <dt>
|
||||||
|
* <pre class="prettyprint">
|
||||||
|
*<external-media-path name="<i>name</i>" path="<i>path</i>" />
|
||||||
|
*</pre>
|
||||||
|
* </dt>
|
||||||
|
* <dd>
|
||||||
|
* Represents files in the root of your app's external media area. The root path of this
|
||||||
|
* subdirectory is the same as the value returned by the first result of
|
||||||
|
* {@link Context#getExternalMediaDirs() Context.getExternalMediaDirs()}.
|
||||||
|
* <p><strong>Note:</strong> this directory is only available on API 21+ devices.</p>
|
||||||
|
* </dd>
|
||||||
|
* </dl>
|
||||||
|
* <p>
|
||||||
|
* These child elements all use the same attributes:
|
||||||
|
* </p>
|
||||||
|
* <dl>
|
||||||
|
* <dt>
|
||||||
|
* <code>name="<i>name</i>"</code>
|
||||||
|
* </dt>
|
||||||
|
* <dd>
|
||||||
|
* A URI path segment. To enforce security, this value hides the name of the subdirectory
|
||||||
|
* you're sharing. The subdirectory name for this value is contained in the
|
||||||
|
* <code>path</code> attribute.
|
||||||
|
* </dd>
|
||||||
|
* <dt>
|
||||||
|
* <code>path="<i>path</i>"</code>
|
||||||
|
* </dt>
|
||||||
|
* <dd>
|
||||||
|
* The subdirectory you're sharing. While the <code>name</code> attribute is a URI path
|
||||||
|
* segment, the <code>path</code> value is an actual subdirectory name. Notice that the
|
||||||
|
* value refers to a <b>subdirectory</b>, not an individual file or files. You can't
|
||||||
|
* share a single file by its file name, nor can you specify a subset of files using
|
||||||
|
* wildcards.
|
||||||
|
* </dd>
|
||||||
|
* </dl>
|
||||||
|
* <p>
|
||||||
|
* You must specify a child element of <code><paths></code> for each directory that contains
|
||||||
|
* files for which you want content URIs. For example, these XML elements specify two directories:
|
||||||
|
* <pre class="prettyprint">
|
||||||
|
*<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
* <files-path name="my_images" path="images/"/>
|
||||||
|
* <files-path name="my_docs" path="docs/"/>
|
||||||
|
*</paths>
|
||||||
|
*</pre>
|
||||||
|
* <p>
|
||||||
|
* Put the <code><paths></code> element and its children in an XML file in your project.
|
||||||
|
* For example, you can add them to a new file called <code>res/xml/file_paths.xml</code>.
|
||||||
|
* To link this file to the FileProvider, add a
|
||||||
|
* <a href="{@docRoot}guide/topics/manifest/meta-data-element.html"><meta-data></a> element
|
||||||
|
* as a child of the <code><provider></code> element that defines the FileProvider. Set the
|
||||||
|
* <code><meta-data></code> element's "android:name" attribute to
|
||||||
|
* <code>android.support.FILE_PROVIDER_PATHS</code>. Set the element's "android:resource" attribute
|
||||||
|
* to <code>@xml/file_paths</code> (notice that you don't specify the <code>.xml</code>
|
||||||
|
* extension). For example:
|
||||||
|
* <pre class="prettyprint">
|
||||||
|
*<provider
|
||||||
|
* android:name="androidx.core.content.FileProvider"
|
||||||
|
* android:authorities="com.mydomain.fileprovider"
|
||||||
|
* android:exported="false"
|
||||||
|
* android:grantUriPermissions="true">
|
||||||
|
* <meta-data
|
||||||
|
* android:name="android.support.FILE_PROVIDER_PATHS"
|
||||||
|
* android:resource="@xml/file_paths" />
|
||||||
|
*</provider>
|
||||||
|
*</pre>
|
||||||
|
* <h3 id="GetUri">Generating the Content URI for a File</h3>
|
||||||
|
* <p>
|
||||||
|
* To share a file with another app using a content URI, your app has to generate the content URI.
|
||||||
|
* To generate the content URI, create a new {@link File} for the file, then pass the {@link File}
|
||||||
|
* to {@link #getUriForFile(Context, String, File) getUriForFile()}. You can send the content URI
|
||||||
|
* returned by {@link #getUriForFile(Context, String, File) getUriForFile()} to another app in an
|
||||||
|
* {@link Intent}. The client app that receives the content URI can open the file
|
||||||
|
* and access its contents by calling
|
||||||
|
* {@link android.content.ContentResolver#openFileDescriptor(Uri, String)
|
||||||
|
* ContentResolver.openFileDescriptor} to get a {@link ParcelFileDescriptor}.
|
||||||
|
* <p>
|
||||||
|
* For example, suppose your app is offering files to other apps with a FileProvider that has the
|
||||||
|
* authority <code>com.mydomain.fileprovider</code>. To get a content URI for the file
|
||||||
|
* <code>default_image.jpg</code> in the <code>images/</code> subdirectory of your internal storage
|
||||||
|
* add the following code:
|
||||||
|
* <pre class="prettyprint">
|
||||||
|
*File imagePath = new File(Context.getFilesDir(), "images");
|
||||||
|
*File newFile = new File(imagePath, "default_image.jpg");
|
||||||
|
*Uri contentUri = getUriForFile(getContext(), "com.mydomain.fileprovider", newFile);
|
||||||
|
*</pre>
|
||||||
|
* As a result of the previous snippet,
|
||||||
|
* {@link #getUriForFile(Context, String, File) getUriForFile()} returns the content URI
|
||||||
|
* <code>content://com.mydomain.fileprovider/my_images/default_image.jpg</code>.
|
||||||
|
* <h3 id="Permissions">Granting Temporary Permissions to a URI</h3>
|
||||||
|
* To grant an access permission to a content URI returned from
|
||||||
|
* {@link #getUriForFile(Context, String, File) getUriForFile()}, do one of the following:
|
||||||
|
* <ul>
|
||||||
|
* <li>
|
||||||
|
* Call the method
|
||||||
|
* {@link Context#grantUriPermission(String, Uri, int)
|
||||||
|
* Context.grantUriPermission(package, Uri, mode_flags)} for the <code>content://</code>
|
||||||
|
* {@link Uri}, using the desired mode flags. This grants temporary access permission for the
|
||||||
|
* content URI to the specified package, according to the value of the
|
||||||
|
* the <code>mode_flags</code> parameter, which you can set to
|
||||||
|
* {@link Intent#FLAG_GRANT_READ_URI_PERMISSION}, {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION}
|
||||||
|
* or both. The permission remains in effect until you revoke it by calling
|
||||||
|
* {@link Context#revokeUriPermission(Uri, int) revokeUriPermission()} or until the device
|
||||||
|
* reboots.
|
||||||
|
* </li>
|
||||||
|
* <li>
|
||||||
|
* Put the content URI in an {@link Intent} by calling {@link Intent#setData(Uri) setData()}.
|
||||||
|
* </li>
|
||||||
|
* <li>
|
||||||
|
* Next, call the method {@link Intent#setFlags(int) Intent.setFlags()} with either
|
||||||
|
* {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} or
|
||||||
|
* {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION} or both.
|
||||||
|
* </li>
|
||||||
|
* <li>
|
||||||
|
* Finally, send the {@link Intent} to
|
||||||
|
* another app. Most often, you do this by calling
|
||||||
|
* {@link android.app.Activity#setResult(int, Intent) setResult()}.
|
||||||
|
* <p>
|
||||||
|
* Permissions granted in an {@link Intent} remain in effect while the stack of the receiving
|
||||||
|
* {@link android.app.Activity} is active. When the stack finishes, the permissions are
|
||||||
|
* automatically removed. Permissions granted to one {@link android.app.Activity} in a client
|
||||||
|
* app are automatically extended to other components of that app.
|
||||||
|
* </p>
|
||||||
|
* </li>
|
||||||
|
* </ul>
|
||||||
|
* <h3 id="ServeUri">Serving a Content URI to Another App</h3>
|
||||||
|
* <p>
|
||||||
|
* There are a variety of ways to serve the content URI for a file to a client app. One common way
|
||||||
|
* is for the client app to start your app by calling
|
||||||
|
* {@link android.app.Activity#startActivityForResult(Intent, int, Bundle) startActivityResult()},
|
||||||
|
* which sends an {@link Intent} to your app to start an {@link android.app.Activity} in your app.
|
||||||
|
* In response, your app can immediately return a content URI to the client app or present a user
|
||||||
|
* interface that allows the user to pick a file. In the latter case, once the user picks the file
|
||||||
|
* your app can return its content URI. In both cases, your app returns the content URI in an
|
||||||
|
* {@link Intent} sent via {@link android.app.Activity#setResult(int, Intent) setResult()}.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* You can also put the content URI in a {@link android.content.ClipData} object and then add the
|
||||||
|
* object to an {@link Intent} you send to a client app. To do this, call
|
||||||
|
* {@link Intent#setClipData(ClipData) Intent.setClipData()}. When you use this approach, you can
|
||||||
|
* add multiple {@link android.content.ClipData} objects to the {@link Intent}, each with its own
|
||||||
|
* content URI. When you call {@link Intent#setFlags(int) Intent.setFlags()} on the {@link Intent}
|
||||||
|
* to set temporary access permissions, the same permissions are applied to all of the content
|
||||||
|
* URIs.
|
||||||
|
* </p>
|
||||||
|
* <p class="note">
|
||||||
|
* <strong>Note:</strong> The {@link Intent#setClipData(ClipData) Intent.setClipData()} method is
|
||||||
|
* only available in platform version 16 (Android 4.1) and later. If you want to maintain
|
||||||
|
* compatibility with previous versions, you should send one content URI at a time in the
|
||||||
|
* {@link Intent}. Set the action to {@link Intent#ACTION_SEND} and put the URI in data by calling
|
||||||
|
* {@link Intent#setData setData()}.
|
||||||
|
* </p>
|
||||||
|
* <h3 id="">More Information</h3>
|
||||||
|
* <p>
|
||||||
|
* To learn more about FileProvider, see the Android training class
|
||||||
|
* <a href="{@docRoot}training/secure-file-sharing/index.html">Sharing Files Securely with URIs</a>.
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
|
public class FileProvider extends ContentProvider {
|
||||||
|
private static final String[] COLUMNS = {
|
||||||
|
OpenableColumns.DISPLAY_NAME, OpenableColumns.SIZE };
|
||||||
|
|
||||||
|
private static final String
|
||||||
|
META_DATA_FILE_PROVIDER_PATHS = "android.support.FILE_PROVIDER_PATHS";
|
||||||
|
|
||||||
|
private static final String TAG_ROOT_PATH = "root-path";
|
||||||
|
private static final String TAG_FILES_PATH = "files-path";
|
||||||
|
private static final String TAG_CACHE_PATH = "cache-path";
|
||||||
|
private static final String TAG_EXTERNAL = "external-path";
|
||||||
|
private static final String TAG_EXTERNAL_FILES = "external-files-path";
|
||||||
|
private static final String TAG_EXTERNAL_CACHE = "external-cache-path";
|
||||||
|
private static final String TAG_EXTERNAL_MEDIA = "external-media-path";
|
||||||
|
|
||||||
|
private static final String ATTR_NAME = "name";
|
||||||
|
private static final String ATTR_PATH = "path";
|
||||||
|
|
||||||
|
private static final File DEVICE_ROOT = new File("/");
|
||||||
|
|
||||||
|
@GuardedBy("sCache")
|
||||||
|
private static HashMap<String, PathStrategy> sCache = new HashMap<String, PathStrategy>();
|
||||||
|
|
||||||
|
private PathStrategy mStrategy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The default FileProvider implementation does not need to be initialized. If you want to
|
||||||
|
* override this method, you must provide your own subclass of FileProvider.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean onCreate() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* After the FileProvider is instantiated, this method is called to provide the system with
|
||||||
|
* information about the provider.
|
||||||
|
*
|
||||||
|
* @param context A {@link Context} for the current component.
|
||||||
|
* @param info A {@link ProviderInfo} for the new provider.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void attachInfo(@NonNull Context context, @NonNull ProviderInfo info) {
|
||||||
|
super.attachInfo(context, info);
|
||||||
|
|
||||||
|
// Sanity check our security
|
||||||
|
if (info.exported) {
|
||||||
|
throw new SecurityException("Provider must not be exported");
|
||||||
|
}
|
||||||
|
if (!info.grantUriPermissions) {
|
||||||
|
throw new SecurityException("Provider must grant uri permissions");
|
||||||
|
}
|
||||||
|
|
||||||
|
mStrategy = getPathStrategy(context, info.authority);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a content URI for a given {@link File}. Specific temporary
|
||||||
|
* permissions for the content URI can be set with
|
||||||
|
* {@link Context#grantUriPermission(String, Uri, int)}, or added
|
||||||
|
* to an {@link Intent} by calling {@link Intent#setData(Uri) setData()} and then
|
||||||
|
* {@link Intent#setFlags(int) setFlags()}; in both cases, the applicable flags are
|
||||||
|
* {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and
|
||||||
|
* {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION}. A FileProvider can only return a
|
||||||
|
* <code>content</code> {@link Uri} for file paths defined in their <code><paths></code>
|
||||||
|
* meta-data element. See the Class Overview for more information.
|
||||||
|
*
|
||||||
|
* @param context A {@link Context} for the current component.
|
||||||
|
* @param authority The authority of a {@link FileProvider} defined in a
|
||||||
|
* {@code <provider>} element in your app's manifest.
|
||||||
|
* @param file A {@link File} pointing to the filename for which you want a
|
||||||
|
* <code>content</code> {@link Uri}.
|
||||||
|
* @return A content URI for the file.
|
||||||
|
* @throws IllegalArgumentException When the given {@link File} is outside
|
||||||
|
* the paths supported by the provider.
|
||||||
|
*/
|
||||||
|
public static Uri getUriForFile(@NonNull Context context, @NonNull String authority,
|
||||||
|
@NonNull File file) {
|
||||||
|
final PathStrategy strategy = getPathStrategy(context, authority);
|
||||||
|
return strategy.getUriForFile(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use a content URI returned by
|
||||||
|
* {@link #getUriForFile(Context, String, File) getUriForFile()} to get information about a file
|
||||||
|
* managed by the FileProvider.
|
||||||
|
* FileProvider reports the column names defined in {@link OpenableColumns}:
|
||||||
|
* <ul>
|
||||||
|
* <li>{@link OpenableColumns#DISPLAY_NAME}</li>
|
||||||
|
* <li>{@link OpenableColumns#SIZE}</li>
|
||||||
|
* </ul>
|
||||||
|
* For more information, see
|
||||||
|
* {@link ContentProvider#query(Uri, String[], String, String[], String)
|
||||||
|
* ContentProvider.query()}.
|
||||||
|
*
|
||||||
|
* @param uri A content URI returned by {@link #getUriForFile}.
|
||||||
|
* @param projection The list of columns to put into the {@link Cursor}. If null all columns are
|
||||||
|
* included.
|
||||||
|
* @param selection Selection criteria to apply. If null then all data that matches the content
|
||||||
|
* URI is returned.
|
||||||
|
* @param selectionArgs An array of {@link String}, containing arguments to bind to
|
||||||
|
* the <i>selection</i> parameter. The <i>query</i> method scans <i>selection</i> from left to
|
||||||
|
* right and iterates through <i>selectionArgs</i>, replacing the current "?" character in
|
||||||
|
* <i>selection</i> with the value at the current position in <i>selectionArgs</i>. The
|
||||||
|
* values are bound to <i>selection</i> as {@link String} values.
|
||||||
|
* @param sortOrder A {@link String} containing the column name(s) on which to sort
|
||||||
|
* the resulting {@link Cursor}.
|
||||||
|
* @return A {@link Cursor} containing the results of the query.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection,
|
||||||
|
@Nullable String[] selectionArgs,
|
||||||
|
@Nullable String sortOrder) {
|
||||||
|
// ContentProvider has already checked granted permissions
|
||||||
|
final File file = mStrategy.getFileForUri(uri);
|
||||||
|
|
||||||
|
if (projection == null) {
|
||||||
|
projection = COLUMNS;
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] cols = new String[projection.length];
|
||||||
|
Object[] values = new Object[projection.length];
|
||||||
|
int i = 0;
|
||||||
|
for (String col : projection) {
|
||||||
|
if (OpenableColumns.DISPLAY_NAME.equals(col)) {
|
||||||
|
cols[i] = OpenableColumns.DISPLAY_NAME;
|
||||||
|
values[i++] = file.getName();
|
||||||
|
} else if (OpenableColumns.SIZE.equals(col)) {
|
||||||
|
cols[i] = OpenableColumns.SIZE;
|
||||||
|
values[i++] = file.length();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cols = copyOf(cols, i);
|
||||||
|
values = copyOf(values, i);
|
||||||
|
|
||||||
|
final MatrixCursor cursor = new MatrixCursor(cols, 1);
|
||||||
|
cursor.addRow(values);
|
||||||
|
return cursor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the MIME type of a content URI returned by
|
||||||
|
* {@link #getUriForFile(Context, String, File) getUriForFile()}.
|
||||||
|
*
|
||||||
|
* @param uri A content URI returned by
|
||||||
|
* {@link #getUriForFile(Context, String, File) getUriForFile()}.
|
||||||
|
* @return If the associated file has an extension, the MIME type associated with that
|
||||||
|
* extension; otherwise <code>application/octet-stream</code>.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getType(@NonNull Uri uri) {
|
||||||
|
// ContentProvider has already checked granted permissions
|
||||||
|
final File file = mStrategy.getFileForUri(uri);
|
||||||
|
|
||||||
|
final int lastDot = file.getName().lastIndexOf('.');
|
||||||
|
if (lastDot >= 0) {
|
||||||
|
final String extension = file.getName().substring(lastDot + 1);
|
||||||
|
final String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
|
||||||
|
if (mime != null) {
|
||||||
|
return mime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "application/octet-stream";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By default, this method throws an {@link UnsupportedOperationException}. You must
|
||||||
|
* subclass FileProvider if you want to provide different functionality.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Uri insert(@NonNull Uri uri, ContentValues values) {
|
||||||
|
throw new UnsupportedOperationException("No external inserts");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By default, this method throws an {@link UnsupportedOperationException}. You must
|
||||||
|
* subclass FileProvider if you want to provide different functionality.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int update(@NonNull Uri uri, ContentValues values, @Nullable String selection,
|
||||||
|
@Nullable String[] selectionArgs) {
|
||||||
|
throw new UnsupportedOperationException("No external updates");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the file associated with the specified content URI, as
|
||||||
|
* returned by {@link #getUriForFile(Context, String, File) getUriForFile()}. Notice that this
|
||||||
|
* method does <b>not</b> throw an {@link IOException}; you must check its return value.
|
||||||
|
*
|
||||||
|
* @param uri A content URI for a file, as returned by
|
||||||
|
* {@link #getUriForFile(Context, String, File) getUriForFile()}.
|
||||||
|
* @param selection Ignored. Set to {@code null}.
|
||||||
|
* @param selectionArgs Ignored. Set to {@code null}.
|
||||||
|
* @return 1 if the delete succeeds; otherwise, 0.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int delete(@NonNull Uri uri, @Nullable String selection,
|
||||||
|
@Nullable String[] selectionArgs) {
|
||||||
|
// ContentProvider has already checked granted permissions
|
||||||
|
final File file = mStrategy.getFileForUri(uri);
|
||||||
|
return file.delete() ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By default, FileProvider automatically returns the
|
||||||
|
* {@link ParcelFileDescriptor} for a file associated with a <code>content://</code>
|
||||||
|
* {@link Uri}. To get the {@link ParcelFileDescriptor}, call
|
||||||
|
* {@link android.content.ContentResolver#openFileDescriptor(Uri, String)
|
||||||
|
* ContentResolver.openFileDescriptor}.
|
||||||
|
*
|
||||||
|
* To override this method, you must provide your own subclass of FileProvider.
|
||||||
|
*
|
||||||
|
* @param uri A content URI associated with a file, as returned by
|
||||||
|
* {@link #getUriForFile(Context, String, File) getUriForFile()}.
|
||||||
|
* @param mode Access mode for the file. May be "r" for read-only access, "rw" for read and
|
||||||
|
* write access, or "rwt" for read and write access that truncates any existing file.
|
||||||
|
* @return A new {@link ParcelFileDescriptor} with which you can access the file.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode)
|
||||||
|
throws FileNotFoundException {
|
||||||
|
// ContentProvider has already checked granted permissions
|
||||||
|
final File file = mStrategy.getFileForUri(uri);
|
||||||
|
final int fileMode = modeToMode(mode);
|
||||||
|
return ParcelFileDescriptor.open(file, fileMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return {@link PathStrategy} for given authority, either by parsing or
|
||||||
|
* returning from cache.
|
||||||
|
*/
|
||||||
|
private static PathStrategy getPathStrategy(Context context, String authority) {
|
||||||
|
PathStrategy strat;
|
||||||
|
synchronized (sCache) {
|
||||||
|
strat = sCache.get(authority);
|
||||||
|
if (strat == null) {
|
||||||
|
try {
|
||||||
|
strat = parsePathStrategy(context, authority);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Failed to parse " + META_DATA_FILE_PROVIDER_PATHS + " meta-data", e);
|
||||||
|
} catch (XmlPullParserException e) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Failed to parse " + META_DATA_FILE_PROVIDER_PATHS + " meta-data", e);
|
||||||
|
}
|
||||||
|
sCache.put(authority, strat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return strat;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse and return {@link PathStrategy} for given authority as defined in
|
||||||
|
* {@link #META_DATA_FILE_PROVIDER_PATHS} {@code <meta-data>}.
|
||||||
|
*
|
||||||
|
* @see #getPathStrategy(Context, String)
|
||||||
|
*/
|
||||||
|
private static PathStrategy parsePathStrategy(Context context, String authority)
|
||||||
|
throws IOException, XmlPullParserException {
|
||||||
|
final SimplePathStrategy strat = new SimplePathStrategy(authority);
|
||||||
|
|
||||||
|
final ProviderInfo info = context.getPackageManager()
|
||||||
|
.resolveContentProvider(authority, PackageManager.GET_META_DATA);
|
||||||
|
if (info == null) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Couldn't find meta-data for provider with authority " + authority);
|
||||||
|
}
|
||||||
|
|
||||||
|
final XmlResourceParser in = info.loadXmlMetaData(
|
||||||
|
context.getPackageManager(), META_DATA_FILE_PROVIDER_PATHS);
|
||||||
|
if (in == null) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Missing " + META_DATA_FILE_PROVIDER_PATHS + " meta-data");
|
||||||
|
}
|
||||||
|
|
||||||
|
int type;
|
||||||
|
while ((type = in.next()) != END_DOCUMENT) {
|
||||||
|
if (type == START_TAG) {
|
||||||
|
final String tag = in.getName();
|
||||||
|
|
||||||
|
final String name = in.getAttributeValue(null, ATTR_NAME);
|
||||||
|
String path = in.getAttributeValue(null, ATTR_PATH);
|
||||||
|
|
||||||
|
File target = null;
|
||||||
|
if (TAG_ROOT_PATH.equals(tag)) {
|
||||||
|
target = DEVICE_ROOT;
|
||||||
|
} else if (TAG_FILES_PATH.equals(tag)) {
|
||||||
|
target = context.getFilesDir();
|
||||||
|
} else if (TAG_CACHE_PATH.equals(tag)) {
|
||||||
|
target = context.getCacheDir();
|
||||||
|
} else if (TAG_EXTERNAL.equals(tag)) {
|
||||||
|
target = Environment.getExternalStorageDirectory();
|
||||||
|
} else if (TAG_EXTERNAL_FILES.equals(tag)) {
|
||||||
|
File[] externalFilesDirs = context.getExternalFilesDirs(null);
|
||||||
|
if (externalFilesDirs.length > 0) {
|
||||||
|
target = externalFilesDirs[0];
|
||||||
|
}
|
||||||
|
} else if (TAG_EXTERNAL_CACHE.equals(tag)) {
|
||||||
|
File[] externalCacheDirs = context.getExternalCacheDirs();
|
||||||
|
if (externalCacheDirs.length > 0) {
|
||||||
|
target = externalCacheDirs[0];
|
||||||
|
}
|
||||||
|
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
|
||||||
|
&& TAG_EXTERNAL_MEDIA.equals(tag)) {
|
||||||
|
File[] externalMediaDirs = context.getExternalMediaDirs();
|
||||||
|
if (externalMediaDirs.length > 0) {
|
||||||
|
target = externalMediaDirs[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (target != null) {
|
||||||
|
strat.addRoot(name, buildPath(target, path));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return strat;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Strategy for mapping between {@link File} and {@link Uri}.
|
||||||
|
* <p>
|
||||||
|
* Strategies must be symmetric so that mapping a {@link File} to a
|
||||||
|
* {@link Uri} and then back to a {@link File} points at the original
|
||||||
|
* target.
|
||||||
|
* <p>
|
||||||
|
* Strategies must remain consistent across app launches, and not rely on
|
||||||
|
* dynamic state. This ensures that any generated {@link Uri} can still be
|
||||||
|
* resolved if your process is killed and later restarted.
|
||||||
|
*
|
||||||
|
* @see SimplePathStrategy
|
||||||
|
*/
|
||||||
|
interface PathStrategy {
|
||||||
|
/**
|
||||||
|
* Return a {@link Uri} that represents the given {@link File}.
|
||||||
|
*/
|
||||||
|
Uri getUriForFile(File file);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a {@link File} that represents the given {@link Uri}.
|
||||||
|
*/
|
||||||
|
File getFileForUri(Uri uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Strategy that provides access to files living under a narrow whitelist of
|
||||||
|
* filesystem roots. It will throw {@link SecurityException} if callers try
|
||||||
|
* accessing files outside the configured roots.
|
||||||
|
* <p>
|
||||||
|
* For example, if configured with
|
||||||
|
* {@code addRoot("myfiles", context.getFilesDir())}, then
|
||||||
|
* {@code context.getFileStreamPath("foo.txt")} would map to
|
||||||
|
* {@code content://myauthority/myfiles/foo.txt}.
|
||||||
|
*/
|
||||||
|
static class SimplePathStrategy implements PathStrategy {
|
||||||
|
private final String mAuthority;
|
||||||
|
private final HashMap<String, File> mRoots = new HashMap<String, File>();
|
||||||
|
|
||||||
|
SimplePathStrategy(String authority) {
|
||||||
|
mAuthority = authority;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a mapping from a name to a filesystem root. The provider only offers
|
||||||
|
* access to files that live under configured roots.
|
||||||
|
*/
|
||||||
|
void addRoot(String name, File root) {
|
||||||
|
if (TextUtils.isEmpty(name)) {
|
||||||
|
throw new IllegalArgumentException("Name must not be empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Resolve to canonical path to keep path checking fast
|
||||||
|
root = root.getCanonicalFile();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Failed to resolve canonical path for " + root, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
mRoots.put(name, root);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Uri getUriForFile(File file) {
|
||||||
|
String path;
|
||||||
|
try {
|
||||||
|
path = file.getCanonicalPath();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IllegalArgumentException("Failed to resolve canonical path for " + file);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the most-specific root path
|
||||||
|
Map.Entry<String, File> mostSpecific = null;
|
||||||
|
for (Map.Entry<String, File> root : mRoots.entrySet()) {
|
||||||
|
final String rootPath = root.getValue().getPath();
|
||||||
|
if (path.startsWith(rootPath) && (mostSpecific == null
|
||||||
|
|| rootPath.length() > mostSpecific.getValue().getPath().length())) {
|
||||||
|
mostSpecific = root;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mostSpecific == null) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Failed to find configured root that contains " + path);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start at first char of path under root
|
||||||
|
final String rootPath = mostSpecific.getValue().getPath();
|
||||||
|
if (rootPath.endsWith("/")) {
|
||||||
|
path = path.substring(rootPath.length());
|
||||||
|
} else {
|
||||||
|
path = path.substring(rootPath.length() + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Encode the tag and path separately
|
||||||
|
path = Uri.encode(mostSpecific.getKey()) + '/' + Uri.encode(path, "/");
|
||||||
|
return new Uri.Builder().scheme("content")
|
||||||
|
.authority(mAuthority).encodedPath(path).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File getFileForUri(Uri uri) {
|
||||||
|
String path = uri.getEncodedPath();
|
||||||
|
|
||||||
|
final int splitIndex = path.indexOf('/', 1);
|
||||||
|
final String tag = Uri.decode(path.substring(1, splitIndex));
|
||||||
|
path = Uri.decode(path.substring(splitIndex + 1));
|
||||||
|
|
||||||
|
final File root = mRoots.get(tag);
|
||||||
|
if (root == null) {
|
||||||
|
throw new IllegalArgumentException("Unable to find configured root for " + uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
File file = new File(root, path);
|
||||||
|
try {
|
||||||
|
file = file.getCanonicalFile();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IllegalArgumentException("Failed to resolve canonical path for " + file);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file.getPath().startsWith(root.getPath())) {
|
||||||
|
throw new SecurityException("Resolved path jumped beyond configured root");
|
||||||
|
}
|
||||||
|
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copied from ContentResolver.java
|
||||||
|
*/
|
||||||
|
private static int modeToMode(String mode) {
|
||||||
|
int modeBits;
|
||||||
|
if ("r".equals(mode)) {
|
||||||
|
modeBits = ParcelFileDescriptor.MODE_READ_ONLY;
|
||||||
|
} else if ("w".equals(mode) || "wt".equals(mode)) {
|
||||||
|
modeBits = ParcelFileDescriptor.MODE_WRITE_ONLY
|
||||||
|
| ParcelFileDescriptor.MODE_CREATE
|
||||||
|
| ParcelFileDescriptor.MODE_TRUNCATE;
|
||||||
|
} else if ("wa".equals(mode)) {
|
||||||
|
modeBits = ParcelFileDescriptor.MODE_WRITE_ONLY
|
||||||
|
| ParcelFileDescriptor.MODE_CREATE
|
||||||
|
| ParcelFileDescriptor.MODE_APPEND;
|
||||||
|
} else if ("rw".equals(mode)) {
|
||||||
|
modeBits = ParcelFileDescriptor.MODE_READ_WRITE
|
||||||
|
| ParcelFileDescriptor.MODE_CREATE;
|
||||||
|
} else if ("rwt".equals(mode)) {
|
||||||
|
modeBits = ParcelFileDescriptor.MODE_READ_WRITE
|
||||||
|
| ParcelFileDescriptor.MODE_CREATE
|
||||||
|
| ParcelFileDescriptor.MODE_TRUNCATE;
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Invalid mode: " + mode);
|
||||||
|
}
|
||||||
|
return modeBits;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static File buildPath(File base, String... segments) {
|
||||||
|
File cur = base;
|
||||||
|
for (String segment : segments) {
|
||||||
|
if (segment != null) {
|
||||||
|
cur = new File(cur, segment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cur;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String[] copyOf(String[] original, int newLength) {
|
||||||
|
final String[] result = new String[newLength];
|
||||||
|
System.arraycopy(original, 0, result, 0, newLength);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Object[] copyOf(Object[] original, int newLength) {
|
||||||
|
final Object[] result = new Object[newLength];
|
||||||
|
System.arraycopy(original, 0, result, 0, newLength);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,6 +7,9 @@ import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.StringRes;
|
||||||
|
import android.os.Build;
|
||||||
|
|
||||||
import com.google.gson.JsonSyntaxException;
|
import com.google.gson.JsonSyntaxException;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
|
@ -25,6 +28,9 @@ import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.joinmastodon.android.api.session.AccountSessionManager;
|
||||||
|
import org.joinmastodon.android.model.Account;
|
||||||
|
|
||||||
public class GlobalUserPreferences{
|
public class GlobalUserPreferences{
|
||||||
private static final String TAG="GlobalUserPreferences";
|
private static final String TAG="GlobalUserPreferences";
|
||||||
|
|
||||||
|
@ -51,7 +57,6 @@ public class GlobalUserPreferences{
|
||||||
public static boolean spectatorMode;
|
public static boolean spectatorMode;
|
||||||
public static boolean autoHideFab;
|
public static boolean autoHideFab;
|
||||||
public static boolean allowRemoteLoading;
|
public static boolean allowRemoteLoading;
|
||||||
public static boolean forwardReportDefault;
|
|
||||||
public static AutoRevealMode autoRevealEqualSpoilers;
|
public static AutoRevealMode autoRevealEqualSpoilers;
|
||||||
public static boolean disableM3PillActiveIndicator;
|
public static boolean disableM3PillActiveIndicator;
|
||||||
public static boolean showNavigationLabels;
|
public static boolean showNavigationLabels;
|
||||||
|
@ -62,10 +67,30 @@ public class GlobalUserPreferences{
|
||||||
public static ColorPreference color;
|
public static ColorPreference color;
|
||||||
public static boolean likeIcon;
|
public static boolean likeIcon;
|
||||||
|
|
||||||
private static SharedPreferences getPrefs(){
|
// MOSHIDON
|
||||||
|
public static boolean showDividers;
|
||||||
|
public static boolean relocatePublishButton;
|
||||||
|
public static boolean defaultToUnlistedReplies;
|
||||||
|
public static boolean doubleTapToSearch;
|
||||||
|
public static boolean doubleTapToSwipe;
|
||||||
|
public static boolean confirmBeforeReblog;
|
||||||
|
public static boolean hapticFeedback;
|
||||||
|
public static boolean replyLineAboveHeader;
|
||||||
|
public static boolean swapBookmarkWithBoostAction;
|
||||||
|
public static boolean mentionRebloggerAutomatically;
|
||||||
|
public static boolean showPostsWithoutAlt;
|
||||||
|
public static boolean showMediaPreview;
|
||||||
|
public static boolean removeTrackingParams;
|
||||||
|
|
||||||
|
public static SharedPreferences getPrefs(){
|
||||||
return MastodonApp.context.getSharedPreferences("global", Context.MODE_PRIVATE);
|
return MastodonApp.context.getSharedPreferences("global", Context.MODE_PRIVATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static SharedPreferences getPreReplyPrefs(){
|
||||||
|
return MastodonApp.context.getSharedPreferences("pre_reply_sheets", Context.MODE_PRIVATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static <T> T fromJson(String json, Type type, T orElse){
|
public static <T> T fromJson(String json, Type type, T orElse){
|
||||||
if(json==null) return orElse;
|
if(json==null) return orElse;
|
||||||
try{
|
try{
|
||||||
|
@ -111,7 +136,6 @@ public class GlobalUserPreferences{
|
||||||
autoHideFab=prefs.getBoolean("autoHideFab", true);
|
autoHideFab=prefs.getBoolean("autoHideFab", true);
|
||||||
allowRemoteLoading=prefs.getBoolean("allowRemoteLoading", true);
|
allowRemoteLoading=prefs.getBoolean("allowRemoteLoading", true);
|
||||||
autoRevealEqualSpoilers=AutoRevealMode.valueOf(prefs.getString("autoRevealEqualSpoilers", AutoRevealMode.THREADS.name()));
|
autoRevealEqualSpoilers=AutoRevealMode.valueOf(prefs.getString("autoRevealEqualSpoilers", AutoRevealMode.THREADS.name()));
|
||||||
forwardReportDefault=prefs.getBoolean("forwardReportDefault", true);
|
|
||||||
disableM3PillActiveIndicator=prefs.getBoolean("disableM3PillActiveIndicator", false);
|
disableM3PillActiveIndicator=prefs.getBoolean("disableM3PillActiveIndicator", false);
|
||||||
showNavigationLabels=prefs.getBoolean("showNavigationLabels", true);
|
showNavigationLabels=prefs.getBoolean("showNavigationLabels", true);
|
||||||
displayPronounsInTimelines=prefs.getBoolean("displayPronounsInTimelines", true);
|
displayPronounsInTimelines=prefs.getBoolean("displayPronounsInTimelines", true);
|
||||||
|
@ -123,6 +147,25 @@ public class GlobalUserPreferences{
|
||||||
color=ColorPreference.valueOf(prefs.getString("color", MATERIAL3.name()));
|
color=ColorPreference.valueOf(prefs.getString("color", MATERIAL3.name()));
|
||||||
likeIcon=prefs.getBoolean("likeIcon", false);
|
likeIcon=prefs.getBoolean("likeIcon", false);
|
||||||
|
|
||||||
|
// MOSHIDON
|
||||||
|
uniformNotificationIcon=prefs.getBoolean("uniformNotificationIcon", false);
|
||||||
|
showDividers =prefs.getBoolean("showDividers", false);
|
||||||
|
relocatePublishButton=prefs.getBoolean("relocatePublishButton", true);
|
||||||
|
defaultToUnlistedReplies=prefs.getBoolean("defaultToUnlistedReplies", false);
|
||||||
|
doubleTapToSearch =prefs.getBoolean("doubleTapToSearch", true);
|
||||||
|
doubleTapToSwipe =prefs.getBoolean("doubleTapToSwipe", true);
|
||||||
|
replyLineAboveHeader=prefs.getBoolean("replyLineAboveHeader", true);
|
||||||
|
confirmBeforeReblog=prefs.getBoolean("confirmBeforeReblog", false);
|
||||||
|
hapticFeedback=prefs.getBoolean("hapticFeedback", true);
|
||||||
|
swapBookmarkWithBoostAction=prefs.getBoolean("swapBookmarkWithBoostAction", false);
|
||||||
|
mentionRebloggerAutomatically=prefs.getBoolean("mentionRebloggerAutomatically", false);
|
||||||
|
showPostsWithoutAlt=prefs.getBoolean("showPostsWithoutAlt", true);
|
||||||
|
showMediaPreview=prefs.getBoolean("showMediaPreview", true);
|
||||||
|
removeTrackingParams=prefs.getBoolean("removeTrackingParams", true);
|
||||||
|
|
||||||
|
theme=ThemePreference.values()[prefs.getInt("theme", 0)];
|
||||||
|
|
||||||
|
|
||||||
if (prefs.contains("prefixRepliesWithRe")) {
|
if (prefs.contains("prefixRepliesWithRe")) {
|
||||||
prefixReplies = prefs.getBoolean("prefixRepliesWithRe", false)
|
prefixReplies = prefs.getBoolean("prefixRepliesWithRe", false)
|
||||||
? PrefixRepliesMode.TO_OTHERS : PrefixRepliesMode.NEVER;
|
? PrefixRepliesMode.TO_OTHERS : PrefixRepliesMode.NEVER;
|
||||||
|
@ -168,7 +211,6 @@ public class GlobalUserPreferences{
|
||||||
.putBoolean("autoHideFab", autoHideFab)
|
.putBoolean("autoHideFab", autoHideFab)
|
||||||
.putBoolean("allowRemoteLoading", allowRemoteLoading)
|
.putBoolean("allowRemoteLoading", allowRemoteLoading)
|
||||||
.putString("autoRevealEqualSpoilers", autoRevealEqualSpoilers.name())
|
.putString("autoRevealEqualSpoilers", autoRevealEqualSpoilers.name())
|
||||||
.putBoolean("forwardReportDefault", forwardReportDefault)
|
|
||||||
.putBoolean("disableM3PillActiveIndicator", disableM3PillActiveIndicator)
|
.putBoolean("disableM3PillActiveIndicator", disableM3PillActiveIndicator)
|
||||||
.putBoolean("showNavigationLabels", showNavigationLabels)
|
.putBoolean("showNavigationLabels", showNavigationLabels)
|
||||||
.putBoolean("displayPronounsInTimelines", displayPronounsInTimelines)
|
.putBoolean("displayPronounsInTimelines", displayPronounsInTimelines)
|
||||||
|
@ -179,15 +221,61 @@ public class GlobalUserPreferences{
|
||||||
.putBoolean("underlinedLinks", underlinedLinks)
|
.putBoolean("underlinedLinks", underlinedLinks)
|
||||||
.putString("color", color.name())
|
.putString("color", color.name())
|
||||||
.putBoolean("likeIcon", likeIcon)
|
.putBoolean("likeIcon", likeIcon)
|
||||||
|
|
||||||
|
// MOSHIDON
|
||||||
|
.putBoolean("defaultToUnlistedReplies", defaultToUnlistedReplies)
|
||||||
|
.putBoolean("doubleTapToSearch", doubleTapToSearch)
|
||||||
|
.putBoolean("doubleTapToSwipe", doubleTapToSwipe)
|
||||||
|
.putBoolean("replyLineAboveHeader", replyLineAboveHeader)
|
||||||
|
.putBoolean("confirmBeforeReblog", confirmBeforeReblog)
|
||||||
|
.putBoolean("swapBookmarkWithBoostAction", swapBookmarkWithBoostAction)
|
||||||
|
.putBoolean("hapticFeedback", hapticFeedback)
|
||||||
|
.putBoolean("mentionRebloggerAutomatically", mentionRebloggerAutomatically)
|
||||||
|
.putBoolean("showDividers", showDividers)
|
||||||
|
.putBoolean("relocatePublishButton", relocatePublishButton)
|
||||||
|
.putBoolean("enableDeleteNotifications", enableDeleteNotifications)
|
||||||
|
.putBoolean("showPostsWithoutAlt", showPostsWithoutAlt)
|
||||||
|
.putBoolean("showMediaPreview", showMediaPreview)
|
||||||
|
.putBoolean("removeTrackingParams", removeTrackingParams)
|
||||||
|
|
||||||
.apply();
|
.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isOptedOutOfPreReplySheet(PreReplySheetType type, Account account, String accountID){
|
||||||
|
if(getPreReplyPrefs().getBoolean("opt_out_"+type, false))
|
||||||
|
return true;
|
||||||
|
if(account==null)
|
||||||
|
return false;
|
||||||
|
String accountKey=account.acct;
|
||||||
|
if(!accountKey.contains("@"))
|
||||||
|
accountKey+="@"+AccountSessionManager.get(accountID).domain;
|
||||||
|
return getPreReplyPrefs().getBoolean("opt_out_"+type+"_"+accountKey.toLowerCase(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void optOutOfPreReplySheet(PreReplySheetType type, Account account, String accountID){
|
||||||
|
String key;
|
||||||
|
if(account==null){
|
||||||
|
key="opt_out_"+type;
|
||||||
|
}else{
|
||||||
|
String accountKey=account.acct;
|
||||||
|
if(!accountKey.contains("@"))
|
||||||
|
accountKey+="@"+AccountSessionManager.get(accountID).domain;
|
||||||
|
key="opt_out_"+type+"_"+accountKey.toLowerCase();
|
||||||
|
}
|
||||||
|
getPreReplyPrefs().edit().putBoolean(key, true).apply();
|
||||||
|
}
|
||||||
|
|
||||||
public enum ThemePreference{
|
public enum ThemePreference{
|
||||||
AUTO,
|
AUTO,
|
||||||
LIGHT,
|
LIGHT,
|
||||||
DARK
|
DARK
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum PreReplySheetType{
|
||||||
|
OLD_POST,
|
||||||
|
NON_MUTUAL
|
||||||
|
}
|
||||||
|
|
||||||
public enum AutoRevealMode {
|
public enum AutoRevealMode {
|
||||||
NEVER,
|
NEVER,
|
||||||
THREADS,
|
THREADS,
|
||||||
|
@ -252,5 +340,4 @@ public class GlobalUserPreferences{
|
||||||
}
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,21 @@
|
||||||
package org.joinmastodon.android;
|
package org.joinmastodon.android;
|
||||||
|
|
||||||
|
import static org.joinmastodon.android.fragments.ComposeFragment.CAMERA_PERMISSION_CODE;
|
||||||
|
import static org.joinmastodon.android.fragments.ComposeFragment.CAMERA_PIC_REQUEST_CODE;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
|
import android.app.Activity;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.app.assist.AssistContent;
|
import android.app.assist.AssistContent;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.BadParcelableException;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.provider.MediaStore;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
|
@ -17,6 +25,7 @@ import org.joinmastodon.android.api.ObjectValidationException;
|
||||||
import org.joinmastodon.android.api.requests.search.GetSearchResults;
|
import org.joinmastodon.android.api.requests.search.GetSearchResults;
|
||||||
import org.joinmastodon.android.api.session.AccountSession;
|
import org.joinmastodon.android.api.session.AccountSession;
|
||||||
import org.joinmastodon.android.api.session.AccountSessionManager;
|
import org.joinmastodon.android.api.session.AccountSessionManager;
|
||||||
|
import org.joinmastodon.android.events.TakePictureRequestEvent;
|
||||||
import org.joinmastodon.android.fragments.ComposeFragment;
|
import org.joinmastodon.android.fragments.ComposeFragment;
|
||||||
import org.joinmastodon.android.fragments.HomeFragment;
|
import org.joinmastodon.android.fragments.HomeFragment;
|
||||||
import org.joinmastodon.android.fragments.ProfileFragment;
|
import org.joinmastodon.android.fragments.ProfileFragment;
|
||||||
|
@ -102,8 +111,6 @@ public class MainActivity extends FragmentStackActivity implements ProvidesAssis
|
||||||
fragment.setArguments(args);
|
fragment.setArguments(args);
|
||||||
showFragmentClearingBackStack(fragment);
|
showFragmentClearingBackStack(fragment);
|
||||||
}
|
}
|
||||||
}else if(intent.getBooleanExtra("compose", false)){
|
|
||||||
showCompose();
|
|
||||||
}else if(Intent.ACTION_VIEW.equals(intent.getAction())){
|
}else if(Intent.ACTION_VIEW.equals(intent.getAction())){
|
||||||
handleURL(intent.getData(), null);
|
handleURL(intent.getData(), null);
|
||||||
}/*else if(intent.hasExtra(PackageInstaller.EXTRA_STATUS) && GithubSelfUpdater.needSelfUpdating()){
|
}/*else if(intent.hasExtra(PackageInstaller.EXTRA_STATUS) && GithubSelfUpdater.needSelfUpdating()){
|
||||||
|
@ -123,11 +130,11 @@ public class MainActivity extends FragmentStackActivity implements ProvidesAssis
|
||||||
session=AccountSessionManager.get(accountID);
|
session=AccountSessionManager.get(accountID);
|
||||||
if(session==null || !session.activated)
|
if(session==null || !session.activated)
|
||||||
return;
|
return;
|
||||||
openSearchQuery(uri.toString(), session.getID(), R.string.opening_link, false);
|
openSearchQuery(uri.toString(), session.getID(), R.string.opening_link, false, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void openSearchQuery(String q, String accountID, int progressText, boolean fromSearch){
|
public void openSearchQuery(String q, String accountID, int progressText, boolean fromSearch, GetSearchResults.Type type){
|
||||||
new GetSearchResults(q, null, true, null, 0, 0)
|
new GetSearchResults(q, type, true, null, 0, 0)
|
||||||
.setCallback(new Callback<>(){
|
.setCallback(new Callback<>(){
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(SearchResults result){
|
public void onSuccess(SearchResults result){
|
||||||
|
@ -178,17 +185,6 @@ public class MainActivity extends FragmentStackActivity implements ProvidesAssis
|
||||||
showFragment(fragment);
|
showFragment(fragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showCompose(){
|
|
||||||
AccountSession session=AccountSessionManager.getInstance().getLastActiveAccount();
|
|
||||||
if(session==null || !session.activated)
|
|
||||||
return;
|
|
||||||
ComposeFragment compose=new ComposeFragment();
|
|
||||||
Bundle composeArgs=new Bundle();
|
|
||||||
composeArgs.putString("account", session.getID());
|
|
||||||
compose.setArguments(composeArgs);
|
|
||||||
showFragment(compose);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void maybeRequestNotificationsPermission(){
|
private void maybeRequestNotificationsPermission(){
|
||||||
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.TIRAMISU && checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS)!=PackageManager.PERMISSION_GRANTED){
|
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.TIRAMISU && checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS)!=PackageManager.PERMISSION_GRANTED){
|
||||||
requestPermissions(new String[]{Manifest.permission.POST_NOTIFICATIONS}, 100);
|
requestPermissions(new String[]{Manifest.permission.POST_NOTIFICATIONS}, 100);
|
||||||
|
@ -227,6 +223,24 @@ public class MainActivity extends FragmentStackActivity implements ProvidesAssis
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// public void onActivityResult(int requestCode, int resultCode, Intent data){
|
||||||
|
// if(requestCode==CAMERA_PIC_REQUEST_CODE && resultCode== Activity.RESULT_OK){
|
||||||
|
// E.post(new TakePictureRequestEvent());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||||
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
|
|
||||||
|
if (requestCode == CAMERA_PERMISSION_CODE && (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
|
||||||
|
E.post(new TakePictureRequestEvent());
|
||||||
|
} else {
|
||||||
|
Toast.makeText(this, R.string.permission_required, Toast.LENGTH_SHORT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Fragment getCurrentFragment() {
|
public Fragment getCurrentFragment() {
|
||||||
for (int i = fragmentContainers.size() - 1; i >= 0; i--) {
|
for (int i = fragmentContainers.size() - 1; i >= 0; i--) {
|
||||||
FrameLayout fl = fragmentContainers.get(i);
|
FrameLayout fl = fragmentContainers.get(i);
|
||||||
|
@ -308,10 +322,14 @@ public class MainActivity extends FragmentStackActivity implements ProvidesAssis
|
||||||
Fragment fragment=session.activated ? new HomeFragment() : new AccountActivationFragment();
|
Fragment fragment=session.activated ? new HomeFragment() : new AccountActivationFragment();
|
||||||
fragment.setArguments(args);
|
fragment.setArguments(args);
|
||||||
if(fromNotification && hasNotification){
|
if(fromNotification && hasNotification){
|
||||||
|
// Parcelables might not be compatible across app versions so this protects against possible crashes
|
||||||
|
// when a notification was received, then the app was updated, and then the user opened the notification
|
||||||
|
try{
|
||||||
Notification notification=Parcels.unwrap(intent.getParcelableExtra("notification"));
|
Notification notification=Parcels.unwrap(intent.getParcelableExtra("notification"));
|
||||||
showFragmentForNotification(notification, session.getID());
|
showFragmentForNotification(notification, session.getID());
|
||||||
} else if (intent.getBooleanExtra("compose", false)){
|
}catch(BadParcelableException x){
|
||||||
showCompose();
|
Log.w(TAG, x);
|
||||||
|
}
|
||||||
} else if (Intent.ACTION_VIEW.equals(intent.getAction())){
|
} else if (Intent.ACTION_VIEW.equals(intent.getAction())){
|
||||||
handleURL(intent.getData(), null);
|
handleURL(intent.getData(), null);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -25,7 +25,7 @@ public class MastodonApp extends Application{
|
||||||
params.diskCacheSize=100*1024*1024;
|
params.diskCacheSize=100*1024*1024;
|
||||||
params.maxMemoryCacheSize=Integer.MAX_VALUE;
|
params.maxMemoryCacheSize=Integer.MAX_VALUE;
|
||||||
ImageCache.setParams(params);
|
ImageCache.setParams(params);
|
||||||
NetworkUtils.setUserAgent("MastodonAndroid/"+BuildConfig.VERSION_NAME);
|
NetworkUtils.setUserAgent("MoshidonAndroid/"+BuildConfig.VERSION_NAME);
|
||||||
|
|
||||||
PushSubscriptionManager.tryRegisterFCM();
|
PushSubscriptionManager.tryRegisterFCM();
|
||||||
GlobalUserPreferences.load();
|
GlobalUserPreferences.load();
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package org.joinmastodon.android;
|
package org.joinmastodon.android;
|
||||||
|
|
||||||
import static org.joinmastodon.android.GlobalUserPreferences.PrefixRepliesMode.*;
|
import static org.joinmastodon.android.GlobalUserPreferences.PrefixRepliesMode.ALWAYS;
|
||||||
|
import static org.joinmastodon.android.GlobalUserPreferences.PrefixRepliesMode.TO_OTHERS;
|
||||||
|
import static org.joinmastodon.android.GlobalUserPreferences.getPrefs;
|
||||||
|
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.NotificationChannel;
|
import android.app.NotificationChannel;
|
||||||
|
@ -12,12 +14,14 @@ import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.opengl.Visibility;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.joinmastodon.android.api.MastodonAPIController;
|
import org.joinmastodon.android.api.MastodonAPIController;
|
||||||
|
import org.joinmastodon.android.api.requests.accounts.SetAccountFollowed;
|
||||||
import org.joinmastodon.android.api.requests.notifications.GetNotificationByID;
|
import org.joinmastodon.android.api.requests.notifications.GetNotificationByID;
|
||||||
import org.joinmastodon.android.api.requests.statuses.CreateStatus;
|
import org.joinmastodon.android.api.requests.statuses.CreateStatus;
|
||||||
import org.joinmastodon.android.api.requests.statuses.SetStatusBookmarked;
|
import org.joinmastodon.android.api.requests.statuses.SetStatusBookmarked;
|
||||||
|
@ -32,6 +36,7 @@ import org.joinmastodon.android.model.Preferences;
|
||||||
import org.joinmastodon.android.model.PushNotification;
|
import org.joinmastodon.android.model.PushNotification;
|
||||||
import org.joinmastodon.android.model.Status;
|
import org.joinmastodon.android.model.Status;
|
||||||
import org.joinmastodon.android.model.StatusPrivacy;
|
import org.joinmastodon.android.model.StatusPrivacy;
|
||||||
|
import org.joinmastodon.android.model.StatusPrivacy;
|
||||||
import org.joinmastodon.android.ui.utils.UiUtils;
|
import org.joinmastodon.android.ui.utils.UiUtils;
|
||||||
import org.parceler.Parcels;
|
import org.parceler.Parcels;
|
||||||
|
|
||||||
|
@ -96,7 +101,7 @@ public class PushNotificationReceiver extends BroadcastReceiver{
|
||||||
}
|
}
|
||||||
String accountID=account.getID();
|
String accountID=account.getID();
|
||||||
PushNotification pn=AccountSessionManager.getInstance().getAccount(accountID).getPushSubscriptionManager().decryptNotification(k, p, s);
|
PushNotification pn=AccountSessionManager.getInstance().getAccount(accountID).getPushSubscriptionManager().decryptNotification(k, p, s);
|
||||||
new GetNotificationByID(pn.notificationId+"")
|
new GetNotificationByID(pn.notificationId)
|
||||||
.setCallback(new Callback<>(){
|
.setCallback(new Callback<>(){
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(org.joinmastodon.android.model.Notification result){
|
public void onSuccess(org.joinmastodon.android.model.Notification result){
|
||||||
|
@ -128,7 +133,11 @@ public class PushNotificationReceiver extends BroadcastReceiver{
|
||||||
|
|
||||||
if(intent.hasExtra("notification")){
|
if(intent.hasExtra("notification")){
|
||||||
org.joinmastodon.android.model.Notification notification=Parcels.unwrap(intent.getParcelableExtra("notification"));
|
org.joinmastodon.android.model.Notification notification=Parcels.unwrap(intent.getParcelableExtra("notification"));
|
||||||
String statusID=notification.status.id;
|
|
||||||
|
String statusID = null;
|
||||||
|
if(notification != null && notification.status != null)
|
||||||
|
statusID=notification.status.id;
|
||||||
|
|
||||||
if (statusID != null) {
|
if (statusID != null) {
|
||||||
AccountSessionManager accountSessionManager = AccountSessionManager.getInstance();
|
AccountSessionManager accountSessionManager = AccountSessionManager.getInstance();
|
||||||
Preferences preferences = accountSessionManager.getAccount(accountID).preferences;
|
Preferences preferences = accountSessionManager.getAccount(accountID).preferences;
|
||||||
|
@ -136,9 +145,10 @@ public class PushNotificationReceiver extends BroadcastReceiver{
|
||||||
switch (NotificationAction.values()[intent.getIntExtra("notificationAction", 0)]) {
|
switch (NotificationAction.values()[intent.getIntExtra("notificationAction", 0)]) {
|
||||||
case FAVORITE -> new SetStatusFavorited(statusID, true).exec(accountID);
|
case FAVORITE -> new SetStatusFavorited(statusID, true).exec(accountID);
|
||||||
case BOOKMARK -> new SetStatusBookmarked(statusID, true).exec(accountID);
|
case BOOKMARK -> new SetStatusBookmarked(statusID, true).exec(accountID);
|
||||||
case REBLOG -> new SetStatusReblogged(notification.status.id, true, preferences.postingDefaultVisibility).exec(accountID);
|
case BOOST -> new SetStatusReblogged(notification.status.id, true, preferences.postingDefaultVisibility).exec(accountID);
|
||||||
case UNDO_REBLOG -> new SetStatusReblogged(notification.status.id, false, preferences.postingDefaultVisibility).exec(accountID);
|
case UNBOOST -> new SetStatusReblogged(notification.status.id, false, preferences.postingDefaultVisibility).exec(accountID);
|
||||||
case REPLY -> handleReplyAction(context, accountID, intent, notification, notificationId, preferences);
|
case REPLY -> handleReplyAction(context, accountID, intent, notification, notificationId, preferences);
|
||||||
|
case FOLLOW_BACK -> new SetAccountFollowed(notification.account.id, true, true, false).exec(accountID);
|
||||||
default -> Log.w(TAG, "onReceive: Failed to get NotificationAction");
|
default -> Log.w(TAG, "onReceive: Failed to get NotificationAction");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,9 +158,9 @@ public class PushNotificationReceiver extends BroadcastReceiver{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void notifyUnifiedPush(Context context, String accountID, org.joinmastodon.android.model.Notification notification) {
|
public void notifyUnifiedPush(Context context, AccountSession account, org.joinmastodon.android.model.Notification notification) {
|
||||||
// push notifications are only created from the official push notification, so we create a fake from by transforming the notification
|
// push notifications are only created from the official push notification, so we create a fake from by transforming the notification
|
||||||
PushNotificationReceiver.this.notify(context, PushNotification.fromNotification(context, notification), accountID, notification);
|
PushNotificationReceiver.this.notify(context, PushNotification.fromNotification(context, account, notification), account.getID(), notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notify(Context context, PushNotification pn, String accountID, org.joinmastodon.android.model.Notification notification){
|
private void notify(Context context, PushNotification pn, String accountID, org.joinmastodon.android.model.Notification notification){
|
||||||
|
@ -205,8 +215,8 @@ public class PushNotificationReceiver extends BroadcastReceiver{
|
||||||
.setShowWhen(true)
|
.setShowWhen(true)
|
||||||
.setCategory(Notification.CATEGORY_SOCIAL)
|
.setCategory(Notification.CATEGORY_SOCIAL)
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
.setLights(UiUtils.getThemeColor(context, android.R.attr.colorAccent), 500, 1000)
|
.setLights(context.getColor(R.color.primary_700), 500, 1000)
|
||||||
.setColor(UiUtils.getThemeColor(context, android.R.attr.colorAccent));
|
.setColor(context.getColor(R.color.shortcut_icon_background));
|
||||||
|
|
||||||
if (!GlobalUserPreferences.uniformNotificationIcon) {
|
if (!GlobalUserPreferences.uniformNotificationIcon) {
|
||||||
builder.setSmallIcon(switch (pn.notificationType) {
|
builder.setSmallIcon(switch (pn.notificationType) {
|
||||||
|
@ -252,14 +262,23 @@ public class PushNotificationReceiver extends BroadcastReceiver{
|
||||||
builder.addAction(buildReplyAction(context, id, accountID, notification));
|
builder.addAction(buildReplyAction(context, id, accountID, notification));
|
||||||
}
|
}
|
||||||
builder.addAction(buildNotificationAction(context, id, accountID, notification, context.getString(R.string.button_favorite), NotificationAction.FAVORITE));
|
builder.addAction(buildNotificationAction(context, id, accountID, notification, context.getString(R.string.button_favorite), NotificationAction.FAVORITE));
|
||||||
builder.addAction(buildNotificationAction(context, id, accountID, notification, context.getString(R.string.add_bookmark), NotificationAction.BOOKMARK));
|
if(GlobalUserPreferences.swapBookmarkWithBoostAction){
|
||||||
if(notification.status.visibility != StatusPrivacy.DIRECT) {
|
if(notification.status.visibility != StatusPrivacy.DIRECT) {
|
||||||
builder.addAction(buildNotificationAction(context, id, accountID, notification, context.getString(R.string.button_reblog), NotificationAction.REBLOG));
|
builder.addAction(buildNotificationAction(context, id, accountID, notification, context.getString(R.string.button_reblog), NotificationAction.BOOST));
|
||||||
|
}else{
|
||||||
|
// This is just so there is a bookmark action if you cannot reblog the toot
|
||||||
|
builder.addAction(buildNotificationAction(context, id, accountID, notification, context.getString(R.string.add_bookmark), NotificationAction.BOOKMARK));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
builder.addAction(buildNotificationAction(context, id, accountID, notification, context.getString(R.string.add_bookmark), NotificationAction.BOOKMARK));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case UPDATE -> {
|
case UPDATE -> {
|
||||||
if(notification.status.reblogged)
|
if(notification.status.reblogged)
|
||||||
builder.addAction(buildNotificationAction(context, id, accountID, notification, context.getString(R.string.sk_undo_reblog), NotificationAction.UNDO_REBLOG));
|
builder.addAction(buildNotificationAction(context, id, accountID, notification, context.getString(R.string.sk_undo_reblog), NotificationAction.UNBOOST));
|
||||||
|
}
|
||||||
|
case FOLLOW -> {
|
||||||
|
builder.addAction(buildNotificationAction(context, id, accountID, notification, context.getString(R.string.follow_back), NotificationAction.FOLLOW_BACK));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -323,7 +342,7 @@ public class PushNotificationReceiver extends BroadcastReceiver{
|
||||||
CreateStatus.Request req=new CreateStatus.Request();
|
CreateStatus.Request req=new CreateStatus.Request();
|
||||||
req.status = initialText + input.toString();
|
req.status = initialText + input.toString();
|
||||||
req.language = notification.status.language;
|
req.language = notification.status.language;
|
||||||
req.visibility = notification.status.visibility;
|
req.visibility = (notification.status.visibility == StatusPrivacy.PUBLIC && GlobalUserPreferences.defaultToUnlistedReplies ? StatusPrivacy.UNLISTED : notification.status.visibility);
|
||||||
req.inReplyToId = notification.status.id;
|
req.inReplyToId = notification.status.id;
|
||||||
|
|
||||||
if (notification.status.hasSpoiler() &&
|
if (notification.status.hasSpoiler() &&
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
package org.joinmastodon.android;
|
||||||
|
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.ParcelFileDescriptor;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
public class TweakedFileProvider extends FileProvider{
|
||||||
|
private static final String TAG="TweakedFileProvider";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType(@NonNull Uri uri){
|
||||||
|
Log.d(TAG, "getType() called with: uri = ["+uri+"]");
|
||||||
|
if(uri.getPathSegments().get(0).equals("image_cache")){
|
||||||
|
Log.i(TAG, "getType: HERE!");
|
||||||
|
return "image/jpeg"; // might as well be a png but image decoding APIs don't care, needs to be image/* though
|
||||||
|
}
|
||||||
|
return super.getType(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder){
|
||||||
|
Log.d(TAG, "query() called with: uri = ["+uri+"], projection = ["+Arrays.toString(projection)+"], selection = ["+selection+"], selectionArgs = ["+Arrays.toString(selectionArgs)+"], sortOrder = ["+sortOrder+"]");
|
||||||
|
return super.query(uri, projection, selection, selectionArgs, sortOrder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode) throws FileNotFoundException{
|
||||||
|
Log.d(TAG, "openFile() called with: uri = ["+uri+"], mode = ["+mode+"]");
|
||||||
|
return super.openFile(uri, mode);
|
||||||
|
}
|
||||||
|
}
|
|
@ -72,7 +72,7 @@ public class UnifiedPushNotificationReceiver extends MessagingReceiver{
|
||||||
result.items
|
result.items
|
||||||
.stream()
|
.stream()
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.ifPresent(value->MastodonAPIController.runInBackground(()->new PushNotificationReceiver().notifyUnifiedPush(context, instance, value)));
|
.ifPresent(value->MastodonAPIController.runInBackground(()->new PushNotificationReceiver().notifyUnifiedPush(context, account, value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -9,21 +9,32 @@ import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
import org.joinmastodon.android.BuildConfig;
|
import org.joinmastodon.android.BuildConfig;
|
||||||
import org.joinmastodon.android.MastodonApp;
|
import org.joinmastodon.android.MastodonApp;
|
||||||
|
import org.joinmastodon.android.api.requests.lists.GetLists;
|
||||||
import org.joinmastodon.android.api.requests.notifications.GetNotifications;
|
import org.joinmastodon.android.api.requests.notifications.GetNotifications;
|
||||||
import org.joinmastodon.android.api.requests.timelines.GetHomeTimeline;
|
import org.joinmastodon.android.api.requests.timelines.GetHomeTimeline;
|
||||||
import org.joinmastodon.android.api.session.AccountSessionManager;
|
import org.joinmastodon.android.api.session.AccountSessionManager;
|
||||||
import org.joinmastodon.android.model.CacheablePaginatedResponse;
|
import org.joinmastodon.android.model.CacheablePaginatedResponse;
|
||||||
import org.joinmastodon.android.model.FilterContext;
|
import org.joinmastodon.android.model.FilterContext;
|
||||||
|
import org.joinmastodon.android.model.FollowList;
|
||||||
import org.joinmastodon.android.model.Instance;
|
import org.joinmastodon.android.model.Instance;
|
||||||
import org.joinmastodon.android.model.Notification;
|
import org.joinmastodon.android.model.Notification;
|
||||||
import org.joinmastodon.android.model.PaginatedResponse;
|
import org.joinmastodon.android.model.PaginatedResponse;
|
||||||
import org.joinmastodon.android.model.SearchResult;
|
import org.joinmastodon.android.model.SearchResult;
|
||||||
import org.joinmastodon.android.model.Status;
|
import org.joinmastodon.android.model.Status;
|
||||||
|
import org.joinmastodon.android.ui.utils.UiUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
@ -44,6 +55,7 @@ public class CacheController{
|
||||||
private final Runnable databaseCloseRunnable=this::closeDatabase;
|
private final Runnable databaseCloseRunnable=this::closeDatabase;
|
||||||
private boolean loadingNotifications;
|
private boolean loadingNotifications;
|
||||||
private final ArrayList<Callback<PaginatedResponse<List<Notification>>>> pendingNotificationsCallbacks=new ArrayList<>();
|
private final ArrayList<Callback<PaginatedResponse<List<Notification>>>> pendingNotificationsCallbacks=new ArrayList<>();
|
||||||
|
private List<FollowList> lists;
|
||||||
|
|
||||||
private static final int POST_FLAG_GAP_AFTER=1;
|
private static final int POST_FLAG_GAP_AFTER=1;
|
||||||
|
|
||||||
|
@ -348,6 +360,99 @@ public class CacheController{
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void reloadLists(Callback<List<FollowList>> callback){
|
||||||
|
new GetLists()
|
||||||
|
.setCallback(new Callback<>(){
|
||||||
|
@Override
|
||||||
|
public void onSuccess(List<FollowList> result){
|
||||||
|
result.sort(Comparator.comparing(l->l.title));
|
||||||
|
lists=result;
|
||||||
|
if(callback!=null)
|
||||||
|
callback.onSuccess(result);
|
||||||
|
writeListsToFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(ErrorResponse error){
|
||||||
|
if(callback!=null)
|
||||||
|
callback.onError(error);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.exec(accountID);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<FollowList> loadListsFromFile(){
|
||||||
|
File file=getListsFile();
|
||||||
|
if(!file.exists())
|
||||||
|
return null;
|
||||||
|
try(InputStreamReader in=new InputStreamReader(new FileInputStream(file))){
|
||||||
|
return MastodonAPIController.gson.fromJson(in, new TypeToken<List<FollowList>>(){}.getType());
|
||||||
|
}catch(Exception x){
|
||||||
|
Log.w(TAG, "failed to read lists from cache file", x);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeListsToFile(){
|
||||||
|
databaseThread.postRunnable(()->{
|
||||||
|
try(OutputStreamWriter out=new OutputStreamWriter(new FileOutputStream(getListsFile()))){
|
||||||
|
MastodonAPIController.gson.toJson(lists, out);
|
||||||
|
}catch(IOException x){
|
||||||
|
Log.w(TAG, "failed to write lists to cache file", x);
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getLists(Callback<List<FollowList>> callback){
|
||||||
|
if(lists!=null){
|
||||||
|
if(callback!=null)
|
||||||
|
callback.onSuccess(lists);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
databaseThread.postRunnable(()->{
|
||||||
|
List<FollowList> lists=loadListsFromFile();
|
||||||
|
if(lists!=null){
|
||||||
|
this.lists=lists;
|
||||||
|
if(callback!=null)
|
||||||
|
uiHandler.post(()->callback.onSuccess(lists));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
reloadLists(callback);
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getListsFile(){
|
||||||
|
return new File(MastodonApp.context.getFilesDir(), "lists_"+accountID+".json");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addList(FollowList list){
|
||||||
|
if(lists==null)
|
||||||
|
return;
|
||||||
|
lists.add(list);
|
||||||
|
lists.sort(Comparator.comparing(l->l.title));
|
||||||
|
writeListsToFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteList(String id){
|
||||||
|
if(lists==null)
|
||||||
|
return;
|
||||||
|
lists.removeIf(l->l.id.equals(id));
|
||||||
|
writeListsToFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateList(FollowList list){
|
||||||
|
if(lists==null)
|
||||||
|
return;
|
||||||
|
for(int i=0;i<lists.size();i++){
|
||||||
|
if(lists.get(i).id.equals(list.id)){
|
||||||
|
lists.set(i, list);
|
||||||
|
lists.sort(Comparator.comparing(l->l.title));
|
||||||
|
writeListsToFile();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class DatabaseHelper extends SQLiteOpenHelper{
|
private class DatabaseHelper extends SQLiteOpenHelper{
|
||||||
|
|
||||||
public DatabaseHelper(){
|
public DatabaseHelper(){
|
||||||
|
|
|
@ -54,7 +54,9 @@ public class MastodonAPIController{
|
||||||
.create();
|
.create();
|
||||||
private static WorkerThread thread=new WorkerThread("MastodonAPIController");
|
private static WorkerThread thread=new WorkerThread("MastodonAPIController");
|
||||||
private static OkHttpClient httpClient=new OkHttpClient.Builder()
|
private static OkHttpClient httpClient=new OkHttpClient.Builder()
|
||||||
.readTimeout(30, TimeUnit.SECONDS)
|
.connectTimeout(60, TimeUnit.SECONDS)
|
||||||
|
.writeTimeout(60, TimeUnit.SECONDS)
|
||||||
|
.readTimeout(60, TimeUnit.SECONDS)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
private AccountSession session;
|
private AccountSession session;
|
||||||
|
@ -89,13 +91,17 @@ public class MastodonAPIController{
|
||||||
final boolean isBad = host == null || badDomains.stream().anyMatch(h -> h.equalsIgnoreCase(host) || host.toLowerCase().endsWith("." + h));
|
final boolean isBad = host == null || badDomains.stream().anyMatch(h -> h.equalsIgnoreCase(host) || host.toLowerCase().endsWith("." + h));
|
||||||
thread.postRunnable(()->{
|
thread.postRunnable(()->{
|
||||||
try{
|
try{
|
||||||
if (isBad) throw new IllegalArgumentException();
|
if(isBad){
|
||||||
|
Log.i(TAG, "submitRequest: refusing to connect to bad domain: " + host);
|
||||||
|
throw new IllegalArgumentException("Failed to connect to domain");
|
||||||
|
}
|
||||||
|
|
||||||
if(req.canceled)
|
if(req.canceled)
|
||||||
return;
|
return;
|
||||||
Request.Builder builder=new Request.Builder()
|
Request.Builder builder=new Request.Builder()
|
||||||
.url(req.getURL().toString())
|
.url(req.getURL().toString())
|
||||||
.method(req.getMethod(), req.getRequestBody())
|
.method(req.getMethod(), req.getRequestBody())
|
||||||
.header("User-Agent", "MegalodonAndroid/"+BuildConfig.VERSION_NAME);
|
.header("User-Agent", "MoshidonAndroid/"+BuildConfig.VERSION_NAME);
|
||||||
|
|
||||||
String token=null;
|
String token=null;
|
||||||
if(session!=null)
|
if(session!=null)
|
||||||
|
@ -122,15 +128,15 @@ public class MastodonAPIController{
|
||||||
}
|
}
|
||||||
|
|
||||||
if(BuildConfig.DEBUG)
|
if(BuildConfig.DEBUG)
|
||||||
Log.d(TAG, "["+(session==null ? "no-auth" : session.getID())+"] Sending request: "+hreq);
|
Log.d(TAG, logTag(session)+"Sending request: "+hreq);
|
||||||
|
|
||||||
call.enqueue(new Callback(){
|
call.enqueue(new Callback(){
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call call, @NonNull IOException e){
|
public void onFailure(@NonNull Call call, @NonNull IOException e){
|
||||||
if(call.isCanceled())
|
if(req.canceled)
|
||||||
return;
|
return;
|
||||||
if(BuildConfig.DEBUG)
|
if(BuildConfig.DEBUG)
|
||||||
Log.w(TAG, "["+(session==null ? "no-auth" : session.getID())+"] "+hreq+" failed", e);
|
Log.w(TAG, logTag(session)+""+hreq+" failed", e);
|
||||||
synchronized(req){
|
synchronized(req){
|
||||||
req.okhttpCall=null;
|
req.okhttpCall=null;
|
||||||
}
|
}
|
||||||
|
@ -139,10 +145,10 @@ public class MastodonAPIController{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException{
|
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException{
|
||||||
if(call.isCanceled())
|
if(req.canceled)
|
||||||
return;
|
return;
|
||||||
if(BuildConfig.DEBUG)
|
if(BuildConfig.DEBUG)
|
||||||
Log.d(TAG, "["+(session==null ? "no-auth" : session.getID())+"] "+hreq+" received response: "+response);
|
Log.d(TAG, logTag(session)+hreq+" received response: "+response);
|
||||||
synchronized(req){
|
synchronized(req){
|
||||||
req.okhttpCall=null;
|
req.okhttpCall=null;
|
||||||
}
|
}
|
||||||
|
@ -153,7 +159,7 @@ public class MastodonAPIController{
|
||||||
try{
|
try{
|
||||||
if(BuildConfig.DEBUG){
|
if(BuildConfig.DEBUG){
|
||||||
JsonElement respJson=JsonParser.parseReader(reader);
|
JsonElement respJson=JsonParser.parseReader(reader);
|
||||||
Log.d(TAG, "["+(session==null ? "no-auth" : session.getID())+"] response body: "+respJson);
|
Log.d(TAG, logTag(session)+"response body: "+respJson);
|
||||||
if(req.respTypeToken!=null)
|
if(req.respTypeToken!=null)
|
||||||
respObj=gson.fromJson(respJson, req.respTypeToken.getType());
|
respObj=gson.fromJson(respJson, req.respTypeToken.getType());
|
||||||
else if(req.respClass!=null)
|
else if(req.respClass!=null)
|
||||||
|
@ -175,7 +181,7 @@ public class MastodonAPIController{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(BuildConfig.DEBUG)
|
if(BuildConfig.DEBUG)
|
||||||
Log.w(TAG, "["+(session==null ? "no-auth" : session.getID())+"] "+response+" error parsing or reading body", x);
|
Log.w(TAG, logTag(session)+response+" error parsing or reading body", x);
|
||||||
req.onError(x.getLocalizedMessage(), response.code(), x);
|
req.onError(x.getLocalizedMessage(), response.code(), x);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -184,19 +190,19 @@ public class MastodonAPIController{
|
||||||
req.validateAndPostprocessResponse(respObj, response);
|
req.validateAndPostprocessResponse(respObj, response);
|
||||||
}catch(IOException x){
|
}catch(IOException x){
|
||||||
if(BuildConfig.DEBUG)
|
if(BuildConfig.DEBUG)
|
||||||
Log.w(TAG, "["+(session==null ? "no-auth" : session.getID())+"] "+response+" error post-processing or validating response", x);
|
Log.w(TAG, logTag(session)+response+" error post-processing or validating response", x);
|
||||||
req.onError(x.getLocalizedMessage(), response.code(), x);
|
req.onError(x.getLocalizedMessage(), response.code(), x);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(BuildConfig.DEBUG)
|
if(BuildConfig.DEBUG)
|
||||||
Log.d(TAG, "["+(session==null ? "no-auth" : session.getID())+"] "+response+" parsed successfully: "+respObj);
|
Log.d(TAG, logTag(session)+response+" parsed successfully: "+respObj);
|
||||||
|
|
||||||
req.onSuccess(respObj);
|
req.onSuccess(respObj);
|
||||||
}else{
|
}else{
|
||||||
try{
|
try{
|
||||||
JsonObject error=JsonParser.parseReader(reader).getAsJsonObject();
|
JsonObject error=JsonParser.parseReader(reader).getAsJsonObject();
|
||||||
Log.w(TAG, "["+(session==null ? "no-auth" : session.getID())+"] "+response+" received error: "+error);
|
Log.w(TAG, logTag(session)+response+" received error: "+error);
|
||||||
if(error.has("details")){
|
if(error.has("details")){
|
||||||
MastodonDetailedErrorResponse err=new MastodonDetailedErrorResponse(error.get("error").getAsString(), response.code(), null);
|
MastodonDetailedErrorResponse err=new MastodonDetailedErrorResponse(error.get("error").getAsString(), response.code(), null);
|
||||||
HashMap<String, List<MastodonDetailedErrorResponse.FieldError>> details=new HashMap<>();
|
HashMap<String, List<MastodonDetailedErrorResponse.FieldError>> details=new HashMap<>();
|
||||||
|
@ -231,7 +237,7 @@ public class MastodonAPIController{
|
||||||
});
|
});
|
||||||
}catch(Exception x){
|
}catch(Exception x){
|
||||||
if(BuildConfig.DEBUG)
|
if(BuildConfig.DEBUG)
|
||||||
Log.w(TAG, "["+(session==null ? "no-auth" : session.getID())+"] error creating and sending http request", x);
|
Log.w(TAG, logTag(session)+"error creating and sending http request", x);
|
||||||
req.onError(x.getLocalizedMessage(), 0, x);
|
req.onError(x.getLocalizedMessage(), 0, x);
|
||||||
}
|
}
|
||||||
}, 0);
|
}, 0);
|
||||||
|
@ -244,4 +250,8 @@ public class MastodonAPIController{
|
||||||
public static OkHttpClient getHttpClient(){
|
public static OkHttpClient getHttpClient(){
|
||||||
return httpClient;
|
return httpClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String logTag(AccountSession session){
|
||||||
|
return "["+(session==null ? "no-auth" : session.getID())+"] ";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,6 +182,8 @@ public abstract class MastodonAPIRequest<T> extends APIRequest<T>{
|
||||||
}
|
}
|
||||||
|
|
||||||
public RequestBody getRequestBody() throws IOException{
|
public RequestBody getRequestBody() throws IOException{
|
||||||
|
if(requestBody instanceof RequestBody rb)
|
||||||
|
return rb;
|
||||||
return requestBody==null ? null : new JsonObjectRequestBody(requestBody);
|
return requestBody==null ? null : new JsonObjectRequestBody(requestBody);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import org.joinmastodon.android.E;
|
||||||
import org.joinmastodon.android.MastodonApp;
|
import org.joinmastodon.android.MastodonApp;
|
||||||
import org.joinmastodon.android.api.requests.statuses.SetStatusBookmarked;
|
import org.joinmastodon.android.api.requests.statuses.SetStatusBookmarked;
|
||||||
import org.joinmastodon.android.api.requests.statuses.SetStatusFavorited;
|
import org.joinmastodon.android.api.requests.statuses.SetStatusFavorited;
|
||||||
|
import org.joinmastodon.android.api.requests.statuses.SetStatusMuted;
|
||||||
import org.joinmastodon.android.api.requests.statuses.SetStatusReblogged;
|
import org.joinmastodon.android.api.requests.statuses.SetStatusReblogged;
|
||||||
import org.joinmastodon.android.api.session.AccountSession;
|
import org.joinmastodon.android.api.session.AccountSession;
|
||||||
import org.joinmastodon.android.api.session.AccountSessionManager;
|
import org.joinmastodon.android.api.session.AccountSessionManager;
|
||||||
|
@ -35,6 +36,7 @@ public class StatusInteractionController{
|
||||||
private final HashMap<String, SetStatusFavorited> runningFavoriteRequests=new HashMap<>();
|
private final HashMap<String, SetStatusFavorited> runningFavoriteRequests=new HashMap<>();
|
||||||
private final HashMap<String, SetStatusReblogged> runningReblogRequests=new HashMap<>();
|
private final HashMap<String, SetStatusReblogged> runningReblogRequests=new HashMap<>();
|
||||||
private final HashMap<String, SetStatusBookmarked> runningBookmarkRequests=new HashMap<>();
|
private final HashMap<String, SetStatusBookmarked> runningBookmarkRequests=new HashMap<>();
|
||||||
|
private final HashMap<String, SetStatusMuted> runningMuteRequests=new HashMap<>();
|
||||||
|
|
||||||
public StatusInteractionController(String accountID, boolean updateCounters) {
|
public StatusInteractionController(String accountID, boolean updateCounters) {
|
||||||
this.accountID=accountID;
|
this.accountID=accountID;
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
package org.joinmastodon.android.api.requests.accounts;
|
||||||
|
|
||||||
|
import org.joinmastodon.android.api.MastodonAPIRequest;
|
||||||
|
import org.joinmastodon.android.api.RequiredField;
|
||||||
|
import org.joinmastodon.android.model.BaseModel;
|
||||||
|
|
||||||
|
public class CheckInviteLink extends MastodonAPIRequest<CheckInviteLink.Response>{
|
||||||
|
public CheckInviteLink(String path){
|
||||||
|
super(HttpMethod.GET, path, Response.class);
|
||||||
|
addHeader("Accept", "application/json");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getPathPrefix(){
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Response extends BaseModel{
|
||||||
|
@RequiredField
|
||||||
|
public String inviteCode;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package org.joinmastodon.android.api.requests.accounts;
|
||||||
|
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
|
import org.joinmastodon.android.api.MastodonAPIRequest;
|
||||||
|
import org.joinmastodon.android.model.FollowList;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GetAccountLists extends MastodonAPIRequest<List<FollowList>>{
|
||||||
|
public GetAccountLists(String id){
|
||||||
|
super(HttpMethod.GET, "/accounts/"+id+"/lists", new TypeToken<>(){});
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,22 +4,23 @@ import org.joinmastodon.android.api.MastodonAPIRequest;
|
||||||
import org.joinmastodon.android.model.Token;
|
import org.joinmastodon.android.model.Token;
|
||||||
|
|
||||||
public class RegisterAccount extends MastodonAPIRequest<Token>{
|
public class RegisterAccount extends MastodonAPIRequest<Token>{
|
||||||
public RegisterAccount(String username, String email, String password, String locale, String reason, String timezone){
|
public RegisterAccount(String username, String email, String password, String locale, String reason, String timezone, String inviteCode){
|
||||||
super(HttpMethod.POST, "/accounts", Token.class);
|
super(HttpMethod.POST, "/accounts", Token.class);
|
||||||
setRequestBody(new Body(username, email, password, locale, reason, timezone));
|
setRequestBody(new Body(username, email, password, locale, reason, timezone, inviteCode));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Body{
|
private static class Body{
|
||||||
public String username, email, password, locale, reason, timeZone;
|
public String username, email, password, locale, reason, timeZone, inviteCode;
|
||||||
public boolean agreement=true;
|
public boolean agreement=true;
|
||||||
|
|
||||||
public Body(String username, String email, String password, String locale, String reason, String timeZone){
|
public Body(String username, String email, String password, String locale, String reason, String timeZone, String inviteCode){
|
||||||
this.username=username;
|
this.username=username;
|
||||||
this.email=email;
|
this.email=email;
|
||||||
this.password=password;
|
this.password=password;
|
||||||
this.locale=locale;
|
this.locale=locale;
|
||||||
this.reason=reason;
|
this.reason=reason;
|
||||||
this.timeZone=timeZone;
|
this.timeZone=timeZone;
|
||||||
|
this.inviteCode=inviteCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package org.joinmastodon.android.api.requests.accounts;
|
||||||
|
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
|
import org.joinmastodon.android.api.MastodonAPIRequest;
|
||||||
|
import org.joinmastodon.android.model.Account;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class SearchAccounts extends MastodonAPIRequest<List<Account>>{
|
||||||
|
public SearchAccounts(String q, int limit, int offset, boolean resolve, boolean following){
|
||||||
|
super(HttpMethod.GET, "/accounts/search", new TypeToken<>(){});
|
||||||
|
addQueryParameter("q", q);
|
||||||
|
if(limit>0)
|
||||||
|
addQueryParameter("limit", limit+"");
|
||||||
|
if(offset>0)
|
||||||
|
addQueryParameter("offset", offset+"");
|
||||||
|
if(resolve)
|
||||||
|
addQueryParameter("resolve", "true");
|
||||||
|
if(following)
|
||||||
|
addQueryParameter("following", "true");
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,15 +4,21 @@ import org.joinmastodon.android.api.MastodonAPIRequest;
|
||||||
import org.joinmastodon.android.model.Relationship;
|
import org.joinmastodon.android.model.Relationship;
|
||||||
|
|
||||||
public class SetAccountMuted extends MastodonAPIRequest<Relationship>{
|
public class SetAccountMuted extends MastodonAPIRequest<Relationship>{
|
||||||
public SetAccountMuted(String id, boolean muted, long duration){
|
public SetAccountMuted(String id, boolean muted, long duration, boolean muteNotifications){
|
||||||
super(HttpMethod.POST, "/accounts/"+id+"/"+(muted ? "mute" : "unmute"), Relationship.class);
|
super(HttpMethod.POST, "/accounts/"+id+"/"+(muted ? "mute" : "unmute"), Relationship.class);
|
||||||
setRequestBody(new Request(duration));
|
if(muted)
|
||||||
|
setRequestBody(new Request(duration, muteNotifications));
|
||||||
|
else{
|
||||||
|
setRequestBody(new Object());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Request{
|
private static class Request{
|
||||||
public long duration;
|
public long duration;
|
||||||
public Request(long duration){
|
public boolean muteNotifications;
|
||||||
|
public Request(long duration, boolean muteNotifications){
|
||||||
this.duration=duration;
|
this.duration=duration;
|
||||||
|
this.muteNotifications=muteNotifications;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ public class UpdateAccountCredentials extends MastodonAPIRequest<Account>{
|
||||||
private Uri avatar, cover;
|
private Uri avatar, cover;
|
||||||
private File avatarFile, coverFile;
|
private File avatarFile, coverFile;
|
||||||
private List<AccountField> fields;
|
private List<AccountField> fields;
|
||||||
|
private Boolean discoverable, indexable;
|
||||||
|
|
||||||
public UpdateAccountCredentials(String displayName, String bio, Uri avatar, Uri cover, List<AccountField> fields){
|
public UpdateAccountCredentials(String displayName, String bio, Uri avatar, Uri cover, List<AccountField> fields){
|
||||||
super(HttpMethod.PATCH, "/accounts/update_credentials", Account.class);
|
super(HttpMethod.PATCH, "/accounts/update_credentials", Account.class);
|
||||||
|
@ -41,6 +42,12 @@ public class UpdateAccountCredentials extends MastodonAPIRequest<Account>{
|
||||||
this.fields=fields;
|
this.fields=fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UpdateAccountCredentials setDiscoverableIndexable(boolean discoverable, boolean indexable){
|
||||||
|
this.discoverable=discoverable;
|
||||||
|
this.indexable=indexable;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RequestBody getRequestBody() throws IOException{
|
public RequestBody getRequestBody() throws IOException{
|
||||||
MultipartBody.Builder bldr=new MultipartBody.Builder()
|
MultipartBody.Builder bldr=new MultipartBody.Builder()
|
||||||
|
@ -58,6 +65,7 @@ public class UpdateAccountCredentials extends MastodonAPIRequest<Account>{
|
||||||
}else if(coverFile!=null){
|
}else if(coverFile!=null){
|
||||||
bldr.addFormDataPart("header", coverFile.getName(), new ResizedImageRequestBody(Uri.fromFile(coverFile), 1500*500, null));
|
bldr.addFormDataPart("header", coverFile.getName(), new ResizedImageRequestBody(Uri.fromFile(coverFile), 1500*500, null));
|
||||||
}
|
}
|
||||||
|
if(fields!=null){
|
||||||
if(fields.isEmpty()){
|
if(fields.isEmpty()){
|
||||||
bldr.addFormDataPart("fields_attributes[0][name]", "").addFormDataPart("fields_attributes[0][value]", "");
|
bldr.addFormDataPart("fields_attributes[0][name]", "").addFormDataPart("fields_attributes[0][value]", "");
|
||||||
}else{
|
}else{
|
||||||
|
@ -67,6 +75,11 @@ public class UpdateAccountCredentials extends MastodonAPIRequest<Account>{
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if(discoverable!=null)
|
||||||
|
bldr.addFormDataPart("discoverable", discoverable.toString());
|
||||||
|
if(indexable!=null)
|
||||||
|
bldr.addFormDataPart("indexable", indexable.toString());
|
||||||
|
|
||||||
return bldr.build();
|
return bldr.build();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,9 @@ package org.joinmastodon.android.api.requests.filters;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
import androidx.annotation.Keep;
|
||||||
|
|
||||||
|
@Keep
|
||||||
class KeywordAttribute{
|
class KeywordAttribute{
|
||||||
public String id;
|
public String id;
|
||||||
@SerializedName("_destroy")
|
@SerializedName("_destroy")
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package org.joinmastodon.android.api.requests.instance;
|
||||||
|
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
|
import org.joinmastodon.android.api.MastodonAPIRequest;
|
||||||
|
import org.joinmastodon.android.model.DomainBlock;
|
||||||
|
import org.joinmastodon.android.model.ExtendedDescription;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GetDomainBlocks extends MastodonAPIRequest<List<DomainBlock>>{
|
||||||
|
public GetDomainBlocks(){
|
||||||
|
super(HttpMethod.GET, "/instance/domain_blocks", new TypeToken<>(){});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package org.joinmastodon.android.api.requests.instance;
|
||||||
|
|
||||||
|
import org.joinmastodon.android.api.MastodonAPIRequest;
|
||||||
|
import org.joinmastodon.android.model.ExtendedDescription;
|
||||||
|
import org.joinmastodon.android.model.Instance;
|
||||||
|
|
||||||
|
public class GetExtendedDescription extends MastodonAPIRequest<ExtendedDescription>{
|
||||||
|
public GetExtendedDescription(){
|
||||||
|
super(HttpMethod.GET, "/instance/extended_description", ExtendedDescription.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package org.joinmastodon.android.api.requests.instance;
|
||||||
|
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
|
import org.joinmastodon.android.api.MastodonAPIRequest;
|
||||||
|
import org.joinmastodon.android.model.WeeklyActivity;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GetWeeklyActivity extends MastodonAPIRequest<List<WeeklyActivity>>{
|
||||||
|
public GetWeeklyActivity(){
|
||||||
|
super(HttpMethod.GET, "/instance/activity", new TypeToken<>(){});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,17 +1,19 @@
|
||||||
package org.joinmastodon.android.api.requests.lists;
|
package org.joinmastodon.android.api.requests.lists;
|
||||||
|
|
||||||
import org.joinmastodon.android.api.MastodonAPIRequest;
|
import org.joinmastodon.android.api.ResultlessMastodonAPIRequest;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class AddAccountsToList extends MastodonAPIRequest<Object> {
|
import java.nio.charset.StandardCharsets;
|
||||||
public AddAccountsToList(String listId, List<String> accountIds){
|
import java.util.Collection;
|
||||||
super(HttpMethod.POST, "/lists/"+listId+"/accounts", Object.class);
|
|
||||||
Request req = new Request();
|
|
||||||
req.accountIds = accountIds;
|
|
||||||
setRequestBody(req);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Request{
|
import okhttp3.FormBody;
|
||||||
public List<String> accountIds;
|
|
||||||
|
public class AddAccountsToList extends ResultlessMastodonAPIRequest{
|
||||||
|
public AddAccountsToList(String listID, Collection<String> accountIDs){
|
||||||
|
super(HttpMethod.POST, "/lists/"+listID+"/accounts");
|
||||||
|
FormBody.Builder builder=new FormBody.Builder(StandardCharsets.UTF_8);
|
||||||
|
for(String id:accountIDs){
|
||||||
|
builder.add("account_ids[]", id);
|
||||||
|
}
|
||||||
|
setRequestBody(builder.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
package org.joinmastodon.android.api.requests.lists;
|
||||||
|
|
||||||
|
import org.joinmastodon.android.api.MastodonAPIRequest;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class AddList extends MastodonAPIRequest<Object> {
|
||||||
|
public AddList(String listName){
|
||||||
|
super(HttpMethod.POST, "/lists", Object.class);
|
||||||
|
Request req = new Request();
|
||||||
|
req.title = listName;
|
||||||
|
setRequestBody(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Request{
|
||||||
|
public String title;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,21 +1,23 @@
|
||||||
package org.joinmastodon.android.api.requests.lists;
|
package org.joinmastodon.android.api.requests.lists;
|
||||||
|
|
||||||
import org.joinmastodon.android.api.MastodonAPIRequest;
|
import org.joinmastodon.android.api.MastodonAPIRequest;
|
||||||
import org.joinmastodon.android.model.ListTimeline;
|
import org.joinmastodon.android.model.FollowList;
|
||||||
|
|
||||||
public class CreateList extends MastodonAPIRequest<ListTimeline> {
|
public class CreateList extends MastodonAPIRequest<FollowList>{
|
||||||
public CreateList(String title, boolean exclusive, ListTimeline.RepliesPolicy repliesPolicy) {
|
public CreateList(String title, FollowList.RepliesPolicy repliesPolicy, boolean exclusive){
|
||||||
super(HttpMethod.POST, "/lists", ListTimeline.class);
|
super(HttpMethod.POST, "/lists", FollowList.class);
|
||||||
Request req = new Request();
|
setRequestBody(new Request(title, repliesPolicy, exclusive));
|
||||||
req.title = title;
|
|
||||||
req.exclusive = exclusive;
|
|
||||||
req.repliesPolicy = repliesPolicy;
|
|
||||||
setRequestBody(req);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Request {
|
private static class Request{
|
||||||
public String title;
|
public String title;
|
||||||
|
public FollowList.RepliesPolicy repliesPolicy;
|
||||||
public boolean exclusive;
|
public boolean exclusive;
|
||||||
public ListTimeline.RepliesPolicy repliesPolicy;
|
|
||||||
|
public Request(String title, FollowList.RepliesPolicy repliesPolicy, boolean exclusive){
|
||||||
|
this.title=title;
|
||||||
|
this.repliesPolicy=repliesPolicy;
|
||||||
|
this.exclusive=exclusive;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
package org.joinmastodon.android.api.requests.lists;
|
package org.joinmastodon.android.api.requests.lists;
|
||||||
|
|
||||||
import org.joinmastodon.android.api.MastodonAPIRequest;
|
import org.joinmastodon.android.api.ResultlessMastodonAPIRequest;
|
||||||
import org.joinmastodon.android.model.ListTimeline;
|
|
||||||
|
|
||||||
public class DeleteList extends MastodonAPIRequest<Object> {
|
public class DeleteList extends ResultlessMastodonAPIRequest{
|
||||||
public DeleteList(String id){
|
public DeleteList(String id){
|
||||||
super(HttpMethod.DELETE, "/lists/" + id, Object.class);
|
super(HttpMethod.DELETE, "/lists/"+id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
package org.joinmastodon.android.api.requests.lists;
|
||||||
|
|
||||||
|
import org.joinmastodon.android.api.MastodonAPIRequest;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class EditListName extends MastodonAPIRequest<Object> {
|
||||||
|
public EditListName(String newListName, String listId){
|
||||||
|
super(HttpMethod.PUT, "/lists/"+listId, Object.class);
|
||||||
|
Request req = new Request();
|
||||||
|
req.title = newListName;
|
||||||
|
setRequestBody(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Request{
|
||||||
|
public String title;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,10 +1,10 @@
|
||||||
package org.joinmastodon.android.api.requests.lists;
|
package org.joinmastodon.android.api.requests.lists;
|
||||||
|
|
||||||
import org.joinmastodon.android.api.MastodonAPIRequest;
|
import org.joinmastodon.android.api.MastodonAPIRequest;
|
||||||
import org.joinmastodon.android.model.ListTimeline;
|
import org.joinmastodon.android.model.FollowList;
|
||||||
|
|
||||||
public class GetList extends MastodonAPIRequest<ListTimeline> {
|
public class GetList extends MastodonAPIRequest<FollowList> {
|
||||||
public GetList(String id) {
|
public GetList(String id) {
|
||||||
super(HttpMethod.GET, "/lists/" + id, ListTimeline.class);
|
super(HttpMethod.GET, "/lists/" + id, FollowList.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
package org.joinmastodon.android.api.requests.lists;
|
||||||
|
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
|
import org.joinmastodon.android.api.requests.HeaderPaginationRequest;
|
||||||
|
import org.joinmastodon.android.model.Account;
|
||||||
|
|
||||||
|
public class GetListAccounts extends HeaderPaginationRequest<Account>{
|
||||||
|
public GetListAccounts(String listID, String maxID, int limit){
|
||||||
|
super(HttpMethod.GET, "/lists/"+listID+"/accounts", new TypeToken<>(){});
|
||||||
|
if(!TextUtils.isEmpty(maxID))
|
||||||
|
addQueryParameter("max_id", maxID);
|
||||||
|
addQueryParameter("limit", String.valueOf(limit));
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,11 +3,11 @@ package org.joinmastodon.android.api.requests.lists;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
import org.joinmastodon.android.api.MastodonAPIRequest;
|
import org.joinmastodon.android.api.MastodonAPIRequest;
|
||||||
import org.joinmastodon.android.model.ListTimeline;
|
import org.joinmastodon.android.model.FollowList;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class GetLists extends MastodonAPIRequest<List<ListTimeline>>{
|
public class GetLists extends MastodonAPIRequest<List<FollowList>>{
|
||||||
public GetLists() {
|
public GetLists() {
|
||||||
super(HttpMethod.GET, "/lists", new TypeToken<>(){});
|
super(HttpMethod.GET, "/lists", new TypeToken<>(){});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
package org.joinmastodon.android.api.requests.lists;
|
package org.joinmastodon.android.api.requests.lists;
|
||||||
|
|
||||||
import org.joinmastodon.android.api.MastodonAPIRequest;
|
import org.joinmastodon.android.api.ResultlessMastodonAPIRequest;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class RemoveAccountsFromList extends MastodonAPIRequest<Object> {
|
import java.nio.charset.StandardCharsets;
|
||||||
public RemoveAccountsFromList(String listId, List<String> accountIds){
|
import java.util.Collection;
|
||||||
super(HttpMethod.DELETE, "/lists/"+listId+"/accounts", Object.class);
|
|
||||||
Request req = new Request();
|
|
||||||
req.accountIds = accountIds;
|
|
||||||
setRequestBody(req);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Request{
|
import okhttp3.FormBody;
|
||||||
public List<String> accountIds;
|
|
||||||
|
public class RemoveAccountsFromList extends ResultlessMastodonAPIRequest{
|
||||||
|
public RemoveAccountsFromList(String listID, Collection<String> accountIDs){
|
||||||
|
super(HttpMethod.DELETE, "/lists/"+listID+"/accounts");
|
||||||
|
FormBody.Builder builder=new FormBody.Builder(StandardCharsets.UTF_8);
|
||||||
|
for(String id:accountIDs){
|
||||||
|
builder.add("account_ids[]", id);
|
||||||
|
}
|
||||||
|
setRequestBody(builder.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
package org.joinmastodon.android.api.requests.lists;
|
||||||
|
|
||||||
|
import org.joinmastodon.android.api.MastodonAPIRequest;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class RemoveList extends MastodonAPIRequest<Object> {
|
||||||
|
public RemoveList(String listId){
|
||||||
|
super(HttpMethod.DELETE, "/lists/"+listId, Object.class);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,15 +1,23 @@
|
||||||
package org.joinmastodon.android.api.requests.lists;
|
package org.joinmastodon.android.api.requests.lists;
|
||||||
|
|
||||||
import org.joinmastodon.android.api.MastodonAPIRequest;
|
import org.joinmastodon.android.api.MastodonAPIRequest;
|
||||||
import org.joinmastodon.android.model.ListTimeline;
|
import org.joinmastodon.android.model.FollowList;
|
||||||
|
|
||||||
public class UpdateList extends MastodonAPIRequest<ListTimeline> {
|
public class UpdateList extends MastodonAPIRequest<FollowList>{
|
||||||
public UpdateList(String id, String title, boolean exclusive, ListTimeline.RepliesPolicy repliesPolicy) {
|
public UpdateList(String listID, String title, FollowList.RepliesPolicy repliesPolicy, boolean exclusive){
|
||||||
super(HttpMethod.PUT, "/lists/" + id, ListTimeline.class);
|
super(HttpMethod.PUT, "/lists/"+listID, FollowList.class);
|
||||||
CreateList.Request req = new CreateList.Request();
|
setRequestBody(new Request(title, repliesPolicy, exclusive));
|
||||||
req.title = title;
|
}
|
||||||
req.exclusive = exclusive;
|
|
||||||
req.repliesPolicy = repliesPolicy;
|
private static class Request{
|
||||||
setRequestBody(req);
|
public String title;
|
||||||
|
public FollowList.RepliesPolicy repliesPolicy;
|
||||||
|
public boolean exclusive;
|
||||||
|
|
||||||
|
public Request(String title, FollowList.RepliesPolicy repliesPolicy, boolean exclusive){
|
||||||
|
this.title=title;
|
||||||
|
this.repliesPolicy=repliesPolicy;
|
||||||
|
this.exclusive=exclusive;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,9 +11,9 @@ public class CreateOAuthApp extends MastodonAPIRequest<Application>{
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Request{
|
private static class Request{
|
||||||
public String clientName="Megalodon";
|
public String clientName="Moshidon";
|
||||||
public String redirectUris=AccountSessionManager.REDIRECT_URI;
|
public String redirectUris=AccountSessionManager.REDIRECT_URI;
|
||||||
public String scopes=AccountSessionManager.SCOPE;
|
public String scopes=AccountSessionManager.SCOPE;
|
||||||
public String website="https://sk22.github.io/megalodon";
|
public String website="https://github.com/LucasGGamerM/moshidon";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,11 @@ public class GetStatusEditHistory extends MastodonAPIRequest<List<Status>>{
|
||||||
s.visibility=StatusPrivacy.PUBLIC;
|
s.visibility=StatusPrivacy.PUBLIC;
|
||||||
s.mentions=Collections.emptyList();
|
s.mentions=Collections.emptyList();
|
||||||
s.tags=Collections.emptyList();
|
s.tags=Collections.emptyList();
|
||||||
if (s.poll != null)
|
if(s.poll!=null){
|
||||||
s.poll.id="fakeID"+i;
|
s.poll.id="fakeID"+i;
|
||||||
|
s.poll.emojis=Collections.emptyList();
|
||||||
|
s.poll.ownVotes=Collections.emptyList();
|
||||||
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
super.validateAndPostprocessResponse(respObj, httpResponse);
|
super.validateAndPostprocessResponse(respObj, httpResponse);
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package org.joinmastodon.android.api.requests.statuses;
|
||||||
|
|
||||||
|
import org.joinmastodon.android.api.MastodonAPIRequest;
|
||||||
|
import org.joinmastodon.android.model.Status;
|
||||||
|
|
||||||
|
public class SetStatusMuted extends MastodonAPIRequest<Status>{
|
||||||
|
public SetStatusMuted(String id, boolean muted){
|
||||||
|
super(HttpMethod.POST, "/statuses/"+id+"/"+(muted ? "mute" : "unmute"), Status.class);
|
||||||
|
setRequestBody(new Object());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package org.joinmastodon.android.api.requests.tags;
|
||||||
|
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
|
import org.joinmastodon.android.api.requests.HeaderPaginationRequest;
|
||||||
|
import org.joinmastodon.android.model.Hashtag;
|
||||||
|
|
||||||
|
public class GetFollowedTags extends HeaderPaginationRequest<Hashtag>{
|
||||||
|
public GetFollowedTags(String maxID, int limit){
|
||||||
|
super(HttpMethod.GET, "/followed_tags", new TypeToken<>(){});
|
||||||
|
if(maxID!=null)
|
||||||
|
addQueryParameter("max_id", maxID);
|
||||||
|
if(limit>0)
|
||||||
|
addQueryParameter("limit", limit+"");
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,7 +10,7 @@ import org.joinmastodon.android.model.Status;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class GetPublicTimeline extends MastodonAPIRequest<List<Status>>{
|
public class GetPublicTimeline extends MastodonAPIRequest<List<Status>>{
|
||||||
public GetPublicTimeline(boolean local, boolean remote, String maxID, int limit, String replyVisibility){
|
public GetPublicTimeline(boolean local, boolean remote, String maxID, String minID, int limit, String sinceID, String replyVisibility){
|
||||||
super(HttpMethod.GET, "/timelines/public", new TypeToken<>(){});
|
super(HttpMethod.GET, "/timelines/public", new TypeToken<>(){});
|
||||||
if(local)
|
if(local)
|
||||||
addQueryParameter("local", "true");
|
addQueryParameter("local", "true");
|
||||||
|
@ -18,6 +18,10 @@ public class GetPublicTimeline extends MastodonAPIRequest<List<Status>>{
|
||||||
addQueryParameter("remote", "true");
|
addQueryParameter("remote", "true");
|
||||||
if(!TextUtils.isEmpty(maxID))
|
if(!TextUtils.isEmpty(maxID))
|
||||||
addQueryParameter("max_id", maxID);
|
addQueryParameter("max_id", maxID);
|
||||||
|
if(!TextUtils.isEmpty(minID))
|
||||||
|
addQueryParameter("min_id", minID);
|
||||||
|
if(!TextUtils.isEmpty(sinceID))
|
||||||
|
addQueryParameter("since_id", sinceID);
|
||||||
if(limit>0)
|
if(limit>0)
|
||||||
addQueryParameter("limit", limit+"");
|
addQueryParameter("limit", limit+"");
|
||||||
if(replyVisibility != null)
|
if(replyVisibility != null)
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package org.joinmastodon.android.api.requests.timelines;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
|
import org.joinmastodon.android.api.MastodonAPIRequest;
|
||||||
|
import org.joinmastodon.android.model.Status;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GetTrendingLinksTimeline extends MastodonAPIRequest<List<Status>>{
|
||||||
|
public GetTrendingLinksTimeline(@NonNull String url, String maxID, String minID, int limit){
|
||||||
|
super(HttpMethod.GET, "/timelines/link/", new TypeToken<>(){});
|
||||||
|
addQueryParameter("url", url);
|
||||||
|
if(maxID!=null)
|
||||||
|
addQueryParameter("max_id", maxID);
|
||||||
|
if(minID!=null)
|
||||||
|
addQueryParameter("min_id", minID);
|
||||||
|
if(limit>0)
|
||||||
|
addQueryParameter("limit", ""+limit);
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,11 +14,16 @@ import org.joinmastodon.android.GlobalUserPreferences;
|
||||||
import org.joinmastodon.android.R;
|
import org.joinmastodon.android.R;
|
||||||
import org.joinmastodon.android.model.ContentType;
|
import org.joinmastodon.android.model.ContentType;
|
||||||
import org.joinmastodon.android.model.Emoji;
|
import org.joinmastodon.android.model.Emoji;
|
||||||
|
import org.joinmastodon.android.model.Emoji;
|
||||||
|
import org.joinmastodon.android.model.PushSubscription;
|
||||||
import org.joinmastodon.android.model.Instance;
|
import org.joinmastodon.android.model.Instance;
|
||||||
import org.joinmastodon.android.model.TimelineDefinition;
|
import org.joinmastodon.android.model.TimelineDefinition;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class AccountLocalPreferences{
|
public class AccountLocalPreferences{
|
||||||
|
@ -47,11 +52,18 @@ public class AccountLocalPreferences{
|
||||||
public ShowEmojiReactions showEmojiReactions;
|
public ShowEmojiReactions showEmojiReactions;
|
||||||
public ColorPreference color;
|
public ColorPreference color;
|
||||||
public ArrayList<Emoji> recentCustomEmoji;
|
public ArrayList<Emoji> recentCustomEmoji;
|
||||||
|
public boolean preReplySheet;
|
||||||
|
|
||||||
private final static Type recentLanguagesType=new TypeToken<ArrayList<String>>() {}.getType();
|
private final static Type recentLanguagesType=new TypeToken<ArrayList<String>>() {}.getType();
|
||||||
private final static Type timelinesType=new TypeToken<ArrayList<TimelineDefinition>>() {}.getType();
|
private final static Type timelinesType=new TypeToken<ArrayList<TimelineDefinition>>() {}.getType();
|
||||||
private final static Type recentCustomEmojiType=new TypeToken<ArrayList<Emoji>>() {}.getType();
|
private final static Type recentCustomEmojiType=new TypeToken<ArrayList<Emoji>>() {}.getType();
|
||||||
|
|
||||||
|
// MOSHIDON
|
||||||
|
// private final static Type recentEmojisType = new TypeToken<Map<String, Integer>>() {}.getType();
|
||||||
|
// public Map<String, Integer> recentEmojis;
|
||||||
|
private final static Type notificationFiltersType = new TypeToken<PushSubscription.Alerts>() {}.getType();
|
||||||
|
public PushSubscription.Alerts notificationFilters;
|
||||||
|
|
||||||
public AccountLocalPreferences(SharedPreferences prefs, AccountSession session){
|
public AccountLocalPreferences(SharedPreferences prefs, AccountSession session){
|
||||||
this.prefs=prefs;
|
this.prefs=prefs;
|
||||||
showInteractionCounts=prefs.getBoolean("interactionCounts", false);
|
showInteractionCounts=prefs.getBoolean("interactionCounts", false);
|
||||||
|
@ -59,6 +71,7 @@ public class AccountLocalPreferences{
|
||||||
revealCWs=prefs.getBoolean("revealCWs", false);
|
revealCWs=prefs.getBoolean("revealCWs", false);
|
||||||
hideSensitiveMedia=prefs.getBoolean("hideSensitive", true);
|
hideSensitiveMedia=prefs.getBoolean("hideSensitive", true);
|
||||||
serverSideFiltersSupported=prefs.getBoolean("serverSideFilters", false);
|
serverSideFiltersSupported=prefs.getBoolean("serverSideFilters", false);
|
||||||
|
// preReplySheet=prefs.getBoolean("preReplySheet", false);
|
||||||
|
|
||||||
// MEGALODON
|
// MEGALODON
|
||||||
Optional<Instance> instance=session.getInstance();
|
Optional<Instance> instance=session.getInstance();
|
||||||
|
@ -78,6 +91,10 @@ public class AccountLocalPreferences{
|
||||||
showEmojiReactions=ShowEmojiReactions.valueOf(prefs.getString("showEmojiReactions", ShowEmojiReactions.HIDE_EMPTY.name()));
|
showEmojiReactions=ShowEmojiReactions.valueOf(prefs.getString("showEmojiReactions", ShowEmojiReactions.HIDE_EMPTY.name()));
|
||||||
color=prefs.contains("color") ? ColorPreference.valueOf(prefs.getString("color", null)) : null;
|
color=prefs.contains("color") ? ColorPreference.valueOf(prefs.getString("color", null)) : null;
|
||||||
recentCustomEmoji=fromJson(prefs.getString("recentCustomEmoji", null), recentCustomEmojiType, new ArrayList<>());
|
recentCustomEmoji=fromJson(prefs.getString("recentCustomEmoji", null), recentCustomEmojiType, new ArrayList<>());
|
||||||
|
|
||||||
|
// MOSHIDON
|
||||||
|
// recentEmojis=fromJson(prefs.getString("recentEmojis", "{}"), recentEmojisType, new HashMap<>());
|
||||||
|
notificationFilters=fromJson(prefs.getString("notificationFilters", gson.toJson(PushSubscription.Alerts.ofAll())), notificationFiltersType, PushSubscription.Alerts.ofAll());
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getNotificationsPauseEndTime(){
|
public long getNotificationsPauseEndTime(){
|
||||||
|
@ -100,6 +117,9 @@ public class AccountLocalPreferences{
|
||||||
.putBoolean("hideSensitive", hideSensitiveMedia)
|
.putBoolean("hideSensitive", hideSensitiveMedia)
|
||||||
.putBoolean("serverSideFilters", serverSideFiltersSupported)
|
.putBoolean("serverSideFilters", serverSideFiltersSupported)
|
||||||
|
|
||||||
|
//TODO figure this stuff out
|
||||||
|
// .putBoolean("preReplySheet", preReplySheet)
|
||||||
|
|
||||||
// MEGALODON
|
// MEGALODON
|
||||||
.putBoolean("showReplies", showReplies)
|
.putBoolean("showReplies", showReplies)
|
||||||
.putBoolean("showBoosts", showBoosts)
|
.putBoolean("showBoosts", showBoosts)
|
||||||
|
@ -117,18 +137,24 @@ public class AccountLocalPreferences{
|
||||||
.putString("showEmojiReactions", showEmojiReactions.name())
|
.putString("showEmojiReactions", showEmojiReactions.name())
|
||||||
.putString("color", color!=null ? color.name() : null)
|
.putString("color", color!=null ? color.name() : null)
|
||||||
.putString("recentCustomEmoji", gson.toJson(recentCustomEmoji))
|
.putString("recentCustomEmoji", gson.toJson(recentCustomEmoji))
|
||||||
|
|
||||||
|
// MOSHIDON
|
||||||
|
// .putString("recentEmojis", gson.toJson(recentEmojis))
|
||||||
|
.putString("notificationFilters", gson.toJson(notificationFilters))
|
||||||
.apply();
|
.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum ColorPreference{
|
public enum ColorPreference{
|
||||||
MATERIAL3,
|
MATERIAL3,
|
||||||
PINK,
|
|
||||||
PURPLE,
|
PURPLE,
|
||||||
|
PINK,
|
||||||
GREEN,
|
GREEN,
|
||||||
BLUE,
|
BLUE,
|
||||||
BROWN,
|
BROWN,
|
||||||
RED,
|
RED,
|
||||||
YELLOW;
|
YELLOW,
|
||||||
|
NORD,
|
||||||
|
WHITE;
|
||||||
|
|
||||||
public @StringRes int getName() {
|
public @StringRes int getName() {
|
||||||
return switch(this){
|
return switch(this){
|
||||||
|
@ -140,6 +166,8 @@ public class AccountLocalPreferences{
|
||||||
case BROWN -> R.string.sk_color_palette_brown;
|
case BROWN -> R.string.sk_color_palette_brown;
|
||||||
case RED -> R.string.sk_color_palette_red;
|
case RED -> R.string.sk_color_palette_red;
|
||||||
case YELLOW -> R.string.sk_color_palette_yellow;
|
case YELLOW -> R.string.sk_color_palette_yellow;
|
||||||
|
case NORD -> R.string.mo_color_palette_nord;
|
||||||
|
case WHITE -> R.string.mo_color_palette_black_and_white;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,11 +21,13 @@ import org.joinmastodon.android.api.requests.markers.SaveMarkers;
|
||||||
import org.joinmastodon.android.api.requests.oauth.RevokeOauthToken;
|
import org.joinmastodon.android.api.requests.oauth.RevokeOauthToken;
|
||||||
import org.joinmastodon.android.events.NotificationsMarkerUpdatedEvent;
|
import org.joinmastodon.android.events.NotificationsMarkerUpdatedEvent;
|
||||||
import org.joinmastodon.android.model.Account;
|
import org.joinmastodon.android.model.Account;
|
||||||
|
import org.joinmastodon.android.model.AltTextFilter;
|
||||||
import org.joinmastodon.android.model.Application;
|
import org.joinmastodon.android.model.Application;
|
||||||
import org.joinmastodon.android.model.FilterAction;
|
import org.joinmastodon.android.model.FilterAction;
|
||||||
import org.joinmastodon.android.model.FilterContext;
|
import org.joinmastodon.android.model.FilterContext;
|
||||||
import org.joinmastodon.android.model.FilterResult;
|
import org.joinmastodon.android.model.FilterResult;
|
||||||
import org.joinmastodon.android.model.Instance;
|
import org.joinmastodon.android.model.Instance;
|
||||||
|
import org.joinmastodon.android.model.FollowList;
|
||||||
import org.joinmastodon.android.model.LegacyFilter;
|
import org.joinmastodon.android.model.LegacyFilter;
|
||||||
import org.joinmastodon.android.model.Preferences;
|
import org.joinmastodon.android.model.Preferences;
|
||||||
import org.joinmastodon.android.model.PushSubscription;
|
import org.joinmastodon.android.model.PushSubscription;
|
||||||
|
@ -34,7 +36,9 @@ import org.joinmastodon.android.model.TimelineMarkers;
|
||||||
import org.joinmastodon.android.model.Token;
|
import org.joinmastodon.android.model.Token;
|
||||||
import org.joinmastodon.android.utils.ObjectIdComparator;
|
import org.joinmastodon.android.utils.ObjectIdComparator;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
@ -70,6 +74,7 @@ public class AccountSession{
|
||||||
private transient SharedPreferences prefs;
|
private transient SharedPreferences prefs;
|
||||||
private transient boolean preferencesNeedSaving;
|
private transient boolean preferencesNeedSaving;
|
||||||
private transient AccountLocalPreferences localPreferences;
|
private transient AccountLocalPreferences localPreferences;
|
||||||
|
private transient List<FollowList> lists;
|
||||||
|
|
||||||
AccountSession(Token token, Account self, Application app, String domain, boolean activated, AccountActivationInfo activationInfo){
|
AccountSession(Token token, Account self, Application app, String domain, boolean activated, AccountActivationInfo activationInfo){
|
||||||
this.token=token;
|
this.token=token;
|
||||||
|
@ -310,8 +315,11 @@ public class AccountSession{
|
||||||
return true;
|
return true;
|
||||||
// Even with server-side filters, clients are expected to remove statuses that match a filter that hides them
|
// Even with server-side filters, clients are expected to remove statuses that match a filter that hides them
|
||||||
if(getLocalPreferences().serverSideFiltersSupported){
|
if(getLocalPreferences().serverSideFiltersSupported){
|
||||||
|
// Moshidon: this code path in CustomLocalTimelines makes the app crash, so this check is here
|
||||||
|
if (s.filtered == null)
|
||||||
|
return false;
|
||||||
for(FilterResult filter : s.filtered){
|
for(FilterResult filter : s.filtered){
|
||||||
if(filter.filter.isActive() && filter.filter.filterAction==FilterAction.HIDE)
|
if(filter.filter.isActive() && filter.filter.filterAction==FilterAction.HIDE && filter.filter.context.contains(context))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}else if(wordFilters!=null){
|
}else if(wordFilters!=null){
|
||||||
|
@ -323,6 +331,21 @@ public class AccountSession{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<FilterResult> getClientSideFilters(Status status) {
|
||||||
|
List<FilterResult> filters = new ArrayList<>();
|
||||||
|
|
||||||
|
// filter post that have no alt text
|
||||||
|
// it only applies when activated in the settings
|
||||||
|
AltTextFilter altTextFilter=new AltTextFilter(FilterAction.WARN, EnumSet.allOf(FilterContext.class));
|
||||||
|
if(altTextFilter.matches(status)){
|
||||||
|
FilterResult filterResult=new FilterResult();
|
||||||
|
filterResult.filter=altTextFilter;
|
||||||
|
filterResult.keywordMatches=List.of();
|
||||||
|
filters.add(filterResult);
|
||||||
|
}
|
||||||
|
return filters;
|
||||||
|
}
|
||||||
|
|
||||||
public void updateAccountInfo(){
|
public void updateAccountInfo(){
|
||||||
AccountSessionManager.getInstance().updateSessionLocalInfo(this);
|
AccountSessionManager.getInstance().updateSessionLocalInfo(this);
|
||||||
}
|
}
|
||||||
|
@ -343,4 +366,12 @@ public class AccountSession{
|
||||||
.map(instance->"https://"+domain+(instance.isAkkoma() ? "/images/avi.png" : "/avatars/original/missing.png"))
|
.map(instance->"https://"+domain+(instance.isAkkoma() ? "/images/avi.png" : "/avatars/original/missing.png"))
|
||||||
.orElse("");
|
.orElse("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isNotificationsMentionsOnly(){
|
||||||
|
return getRawLocalPreferences().getBoolean("notificationsMentionsOnly", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNotificationsMentionsOnly(boolean mentionsOnly){
|
||||||
|
getRawLocalPreferences().edit().putBoolean("notificationsMentionsOnly", mentionsOnly).apply();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package org.joinmastodon.android.api.session;
|
package org.joinmastodon.android.api.session;
|
||||||
|
|
||||||
import static org.unifiedpush.android.connector.UnifiedPush.getDistributor;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
|
@ -17,7 +15,7 @@ import android.util.Log;
|
||||||
|
|
||||||
import org.joinmastodon.android.BuildConfig;
|
import org.joinmastodon.android.BuildConfig;
|
||||||
import org.joinmastodon.android.E;
|
import org.joinmastodon.android.E;
|
||||||
import org.joinmastodon.android.GlobalUserPreferences;
|
import org.joinmastodon.android.ChooseAccountForComposeActivity;
|
||||||
import org.joinmastodon.android.MainActivity;
|
import org.joinmastodon.android.MainActivity;
|
||||||
import org.joinmastodon.android.MastodonApp;
|
import org.joinmastodon.android.MastodonApp;
|
||||||
import org.joinmastodon.android.R;
|
import org.joinmastodon.android.R;
|
||||||
|
@ -64,7 +62,7 @@ import me.grishka.appkit.api.ErrorResponse;
|
||||||
public class AccountSessionManager{
|
public class AccountSessionManager{
|
||||||
private static final String TAG="AccountSessionManager";
|
private static final String TAG="AccountSessionManager";
|
||||||
public static final String SCOPE="read write follow push";
|
public static final String SCOPE="read write follow push";
|
||||||
public static final String REDIRECT_URI="megalodon-android-auth://callback";
|
public static final String REDIRECT_URI = getRedirectURI();
|
||||||
|
|
||||||
private static final AccountSessionManager instance=new AccountSessionManager();
|
private static final AccountSessionManager instance=new AccountSessionManager();
|
||||||
|
|
||||||
|
@ -82,8 +80,20 @@ public class AccountSessionManager{
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getRedirectURI() {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("moshidon-android-");
|
||||||
|
if (BuildConfig.BUILD_TYPE.equals("debug") || BuildConfig.BUILD_TYPE.equals("nightly")) {
|
||||||
|
builder.append(BuildConfig.BUILD_TYPE);
|
||||||
|
builder.append('-');
|
||||||
|
}
|
||||||
|
builder.append("auth://callback");
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
private AccountSessionManager(){
|
private AccountSessionManager(){
|
||||||
prefs=MastodonApp.context.getSharedPreferences("account_manager", Context.MODE_PRIVATE);
|
prefs=MastodonApp.context.getSharedPreferences("account_manager", Context.MODE_PRIVATE);
|
||||||
|
// This file should not be backed up, otherwise the app may start with accounts already logged in. See res/xml/backup_rules.xml
|
||||||
File file=new File(MastodonApp.context.getFilesDir(), "accounts.json");
|
File file=new File(MastodonApp.context.getFilesDir(), "accounts.json");
|
||||||
if(!file.exists())
|
if(!file.exists())
|
||||||
return;
|
return;
|
||||||
|
@ -204,12 +214,17 @@ public class AccountSessionManager{
|
||||||
public void removeAccount(String id){
|
public void removeAccount(String id){
|
||||||
AccountSession session=getAccount(id);
|
AccountSession session=getAccount(id);
|
||||||
session.getCacheController().closeDatabase();
|
session.getCacheController().closeDatabase();
|
||||||
|
session.getCacheController().getListsFile().delete();
|
||||||
MastodonApp.context.deleteDatabase(id+".db");
|
MastodonApp.context.deleteDatabase(id+".db");
|
||||||
MastodonApp.context.getSharedPreferences(id, 0).edit().clear().commit();
|
MastodonApp.context.getSharedPreferences(id, 0).edit().clear().commit();
|
||||||
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.N){
|
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.N){
|
||||||
MastodonApp.context.deleteSharedPreferences(id);
|
MastodonApp.context.deleteSharedPreferences(id);
|
||||||
}else{
|
}else{
|
||||||
new File(MastodonApp.context.getDir("shared_prefs", Context.MODE_PRIVATE), id+".xml").delete();
|
String dataDir=MastodonApp.context.getApplicationInfo().dataDir;
|
||||||
|
if(dataDir!=null){
|
||||||
|
File prefsDir=new File(dataDir, "shared_prefs");
|
||||||
|
new File(prefsDir, id+".xml").delete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sessions.remove(id);
|
sessions.remove(id);
|
||||||
if(lastActiveAccountID.equals(id)){
|
if(lastActiveAccountID.equals(id)){
|
||||||
|
@ -244,7 +259,7 @@ public class AccountSessionManager{
|
||||||
.path("/oauth/authorize")
|
.path("/oauth/authorize")
|
||||||
.appendQueryParameter("response_type", "code")
|
.appendQueryParameter("response_type", "code")
|
||||||
.appendQueryParameter("client_id", result.clientId)
|
.appendQueryParameter("client_id", result.clientId)
|
||||||
.appendQueryParameter("redirect_uri", "megalodon-android-auth://callback")
|
.appendQueryParameter("redirect_uri", REDIRECT_URI)
|
||||||
.appendQueryParameter("scope", SCOPE)
|
.appendQueryParameter("scope", SCOPE)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
@ -468,15 +483,19 @@ public class AccountSessionManager{
|
||||||
if(Build.VERSION.SDK_INT<26)
|
if(Build.VERSION.SDK_INT<26)
|
||||||
return;
|
return;
|
||||||
ShortcutManager sm=MastodonApp.context.getSystemService(ShortcutManager.class);
|
ShortcutManager sm=MastodonApp.context.getSystemService(ShortcutManager.class);
|
||||||
if((sm.getDynamicShortcuts().isEmpty() || BuildConfig.DEBUG) && !sessions.isEmpty()){
|
|
||||||
|
Intent intent = new Intent(MastodonApp.context, ChooseAccountForComposeActivity.class)
|
||||||
|
.setAction(Intent.ACTION_CHOOSER)
|
||||||
|
.putExtra("compose", true);
|
||||||
|
|
||||||
|
// This was done so that the old shortcuts get updated to the new implementation.
|
||||||
|
if((sm.getDynamicShortcuts().isEmpty() || sm.getDynamicShortcuts().get(0).getIntent() != intent || BuildConfig.DEBUG ) && !sessions.isEmpty()){
|
||||||
// There are no shortcuts, but there are accounts. Add a compose shortcut.
|
// There are no shortcuts, but there are accounts. Add a compose shortcut.
|
||||||
ShortcutInfo info=new ShortcutInfo.Builder(MastodonApp.context, "compose")
|
ShortcutInfo info=new ShortcutInfo.Builder(MastodonApp.context, "compose")
|
||||||
.setActivity(ComponentName.createRelative(MastodonApp.context, MainActivity.class.getName()))
|
.setActivity(ComponentName.createRelative(MastodonApp.context, MainActivity.class.getName()))
|
||||||
.setShortLabel(MastodonApp.context.getString(R.string.new_post))
|
.setShortLabel(MastodonApp.context.getString(R.string.new_post))
|
||||||
.setIcon(Icon.createWithResource(MastodonApp.context, R.mipmap.ic_shortcut_compose))
|
.setIcon(Icon.createWithResource(MastodonApp.context, R.mipmap.ic_shortcut_compose))
|
||||||
.setIntent(new Intent(MastodonApp.context, MainActivity.class)
|
.setIntent(intent)
|
||||||
.setAction(Intent.ACTION_MAIN)
|
|
||||||
.putExtra("compose", true))
|
|
||||||
.build();
|
.build();
|
||||||
sm.setDynamicShortcuts(Collections.singletonList(info));
|
sm.setDynamicShortcuts(Collections.singletonList(info));
|
||||||
}else if(sessions.isEmpty()){
|
}else if(sessions.isEmpty()){
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package org.joinmastodon.android.events;
|
||||||
|
|
||||||
|
import org.joinmastodon.android.model.Account;
|
||||||
|
|
||||||
|
public class AccountAddedToListEvent{
|
||||||
|
public final String accountID;
|
||||||
|
public final String listID;
|
||||||
|
public final Account account;
|
||||||
|
|
||||||
|
public AccountAddedToListEvent(String accountID, String listID, Account account){
|
||||||
|
this.accountID=accountID;
|
||||||
|
this.listID=listID;
|
||||||
|
this.account=account;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package org.joinmastodon.android.events;
|
||||||
|
|
||||||
|
public class AccountRemovedFromListEvent{
|
||||||
|
public final String accountID;
|
||||||
|
public final String listID;
|
||||||
|
public final String targetAccountID;
|
||||||
|
|
||||||
|
public AccountRemovedFromListEvent(String accountID, String listID, String targetAccountID){
|
||||||
|
this.accountID=accountID;
|
||||||
|
this.listID=listID;
|
||||||
|
this.targetAccountID=targetAccountID;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package org.joinmastodon.android.events;
|
||||||
|
|
||||||
|
public class FinishListCreationFragmentEvent{
|
||||||
|
public final String accountID;
|
||||||
|
public final String listID;
|
||||||
|
|
||||||
|
public FinishListCreationFragmentEvent(String accountID, String listID){
|
||||||
|
this.accountID=accountID;
|
||||||
|
this.listID=listID;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package org.joinmastodon.android.events;
|
||||||
|
|
||||||
|
import org.joinmastodon.android.model.FollowList;
|
||||||
|
|
||||||
|
public class ListCreatedEvent{
|
||||||
|
public final String accountID;
|
||||||
|
public final FollowList list;
|
||||||
|
|
||||||
|
public ListCreatedEvent(String accountID, FollowList list){
|
||||||
|
this.accountID=accountID;
|
||||||
|
this.list=list;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,11 @@
|
||||||
package org.joinmastodon.android.events;
|
package org.joinmastodon.android.events;
|
||||||
|
|
||||||
public class ListDeletedEvent{
|
public class ListDeletedEvent{
|
||||||
public final String id;
|
public final String accountID;
|
||||||
|
public final String listID;
|
||||||
|
|
||||||
public ListDeletedEvent(String id) {
|
public ListDeletedEvent(String accountID, String listID){
|
||||||
this.id = id;
|
this.accountID=accountID;
|
||||||
|
this.listID=listID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
package org.joinmastodon.android.events;
|
package org.joinmastodon.android.events;
|
||||||
|
|
||||||
import org.joinmastodon.android.model.ListTimeline;
|
import org.joinmastodon.android.model.FollowList;
|
||||||
|
|
||||||
public class ListUpdatedCreatedEvent {
|
public class ListUpdatedCreatedEvent {
|
||||||
public final String id;
|
public final String id;
|
||||||
public final String title;
|
public final String title;
|
||||||
public final ListTimeline.RepliesPolicy repliesPolicy;
|
public final FollowList.RepliesPolicy repliesPolicy;
|
||||||
public final boolean exclusive;
|
public final boolean exclusive;
|
||||||
|
|
||||||
public ListUpdatedCreatedEvent(String id, String title, boolean exclusive, ListTimeline.RepliesPolicy repliesPolicy) {
|
public ListUpdatedCreatedEvent(String id, String title, boolean exclusive, FollowList.RepliesPolicy repliesPolicy) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.exclusive = exclusive;
|
this.exclusive = exclusive;
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
package org.joinmastodon.android.events;
|
||||||
|
|
||||||
|
import org.joinmastodon.android.model.FollowList;
|
||||||
|
|
||||||
|
public class ListUpdatedEvent{
|
||||||
|
public final String accountID;
|
||||||
|
public final FollowList list;
|
||||||
|
|
||||||
|
public ListUpdatedEvent(String accountID, FollowList list){
|
||||||
|
this.accountID=accountID;
|
||||||
|
this.list=list;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package org.joinmastodon.android.events;
|
||||||
|
|
||||||
|
import org.joinmastodon.android.model.Status;
|
||||||
|
|
||||||
|
public class StatusMuteChangedEvent{
|
||||||
|
public String id;
|
||||||
|
public boolean muted;
|
||||||
|
public Status status;
|
||||||
|
|
||||||
|
public StatusMuteChangedEvent(Status s){
|
||||||
|
id=s.id;
|
||||||
|
muted=s.muted;
|
||||||
|
status=s;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
package org.joinmastodon.android.events;
|
||||||
|
|
||||||
|
public class TakePictureRequestEvent {
|
||||||
|
public TakePictureRequestEvent(){
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,114 @@
|
||||||
|
package org.joinmastodon.android.fragments;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.joinmastodon.android.E;
|
||||||
|
import org.joinmastodon.android.R;
|
||||||
|
import org.joinmastodon.android.api.ResultlessMastodonAPIRequest;
|
||||||
|
import org.joinmastodon.android.api.requests.accounts.GetAccountLists;
|
||||||
|
import org.joinmastodon.android.api.requests.lists.AddAccountsToList;
|
||||||
|
import org.joinmastodon.android.api.requests.lists.RemoveAccountsFromList;
|
||||||
|
import org.joinmastodon.android.api.session.AccountSessionManager;
|
||||||
|
import org.joinmastodon.android.events.AccountAddedToListEvent;
|
||||||
|
import org.joinmastodon.android.events.AccountRemovedFromListEvent;
|
||||||
|
import org.joinmastodon.android.fragments.settings.BaseSettingsFragment;
|
||||||
|
import org.joinmastodon.android.model.Account;
|
||||||
|
import org.joinmastodon.android.model.FollowList;
|
||||||
|
import org.joinmastodon.android.model.viewmodel.CheckableListItem;
|
||||||
|
import org.joinmastodon.android.ui.utils.UiUtils;
|
||||||
|
import org.parceler.Parcels;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import me.grishka.appkit.api.Callback;
|
||||||
|
import me.grishka.appkit.api.ErrorResponse;
|
||||||
|
import me.grishka.appkit.api.SimpleCallback;
|
||||||
|
import me.grishka.appkit.utils.MergeRecyclerAdapter;
|
||||||
|
import me.grishka.appkit.utils.SingleViewRecyclerAdapter;
|
||||||
|
import me.grishka.appkit.utils.V;
|
||||||
|
|
||||||
|
public class AddAccountToListsFragment extends BaseSettingsFragment<FollowList>{
|
||||||
|
private Account account;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState){
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setTitle(R.string.add_user_to_list_title);
|
||||||
|
account=Parcels.unwrap(getArguments().getParcelable("targetAccount"));
|
||||||
|
loadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doLoadData(int offset, int count){
|
||||||
|
AccountSessionManager.get(accountID).getCacheController().getLists(new SimpleCallback<>(this){
|
||||||
|
@Override
|
||||||
|
public void onSuccess(List<FollowList> allLists){
|
||||||
|
if(getActivity()==null)
|
||||||
|
return;
|
||||||
|
loadAccountLists(allLists);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadAccountLists(final List<FollowList> allLists){
|
||||||
|
currentRequest=new GetAccountLists(account.id)
|
||||||
|
.setCallback(new SimpleCallback<>(this){
|
||||||
|
@Override
|
||||||
|
public void onSuccess(List<FollowList> result){
|
||||||
|
Set<String> lists=result.stream().map(l->l.id).collect(Collectors.toSet());
|
||||||
|
onDataLoaded(allLists.stream()
|
||||||
|
.map(l->new CheckableListItem<>(l.title, null, CheckableListItem.Style.CHECKBOX, lists.contains(l.id),
|
||||||
|
R.drawable.ic_list_alt_24px, AddAccountToListsFragment.this::onItemClick, l))
|
||||||
|
.collect(Collectors.toList()), false);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.exec(accountID);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int indexOfItemsAdapter(){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected RecyclerView.Adapter<?> getAdapter(){
|
||||||
|
TextView topText=new TextView(getActivity());
|
||||||
|
topText.setTextAppearance(R.style.m3_body_medium);
|
||||||
|
topText.setTextColor(UiUtils.getThemeColor(getActivity(), R.attr.colorM3OnSurface));
|
||||||
|
topText.setPadding(V.dp(16), V.dp(8), V.dp(16), V.dp(8));
|
||||||
|
topText.setText(getString(R.string.manage_user_lists, account.getDisplayUsername()));
|
||||||
|
|
||||||
|
MergeRecyclerAdapter mergeAdapter=new MergeRecyclerAdapter();
|
||||||
|
mergeAdapter.addAdapter(new SingleViewRecyclerAdapter(topText));
|
||||||
|
mergeAdapter.addAdapter(super.getAdapter());
|
||||||
|
return mergeAdapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onItemClick(CheckableListItem<FollowList> item){
|
||||||
|
boolean add=!item.checked;
|
||||||
|
ResultlessMastodonAPIRequest req=add ? new AddAccountsToList(item.parentObject.id, Set.of(account.id)) : new RemoveAccountsFromList(item.parentObject.id, Set.of(account.id));
|
||||||
|
req.setCallback(new Callback<>(){
|
||||||
|
@Override
|
||||||
|
public void onSuccess(Void result){
|
||||||
|
item.checked=add;
|
||||||
|
rebindItem(item);
|
||||||
|
if(add){
|
||||||
|
E.post(new AccountAddedToListEvent(accountID, item.parentObject.id, account));
|
||||||
|
}else{
|
||||||
|
E.post(new AccountRemovedFromListEvent(accountID, item.parentObject.id, account.id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(ErrorResponse error){
|
||||||
|
error.showToast(getActivity());
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.wrapProgress(getActivity(), R.string.loading, false)
|
||||||
|
.exec(accountID);
|
||||||
|
}
|
||||||
|
}
|