diff options
author | Thomas <tschneider.ac@gmail.com> | 2023-01-26 16:47:28 +0100 |
---|---|---|
committer | Thomas <tschneider.ac@gmail.com> | 2023-01-26 16:47:28 +0100 |
commit | 7119c124679bff6239e297ab6231e7f705c3cd29 (patch) | |
tree | 6e4ba1f9d0ac70e4054f590095b69fb59e1dd701 /app | |
parent | 3d1d9534bed500e5448f54f04c4bededd8d01ba2 (diff) |
Remove context dependency
Diffstat (limited to 'app')
10 files changed, 137 insertions, 50 deletions
diff --git a/app/build.gradle b/app/build.gradle index e565bc410..2e03e260f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -171,8 +171,8 @@ dependencies { implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.1.0' implementation 'com.google.android.exoplayer:extension-mediasession:2.18.1' implementation "com.github.mabbas007:TagsEditText:1.0.5" - implementation "net.gotev:uploadservice:4.5.1" - implementation "net.gotev:uploadservice-okhttp:4.5.1" + implementation "net.gotev:uploadservice:4.7.0" + implementation "net.gotev:uploadservice-okhttp:4.7.0" implementation 'androidx.media:media:1.6.0' implementation 'com.github.mancj:MaterialSearchBar:0.8.5' diff --git a/app/src/main/java/app/fedilab/android/MainApplication.java b/app/src/main/java/app/fedilab/android/MainApplication.java index 2e5a57101..e200ae71a 100644 --- a/app/src/main/java/app/fedilab/android/MainApplication.java +++ b/app/src/main/java/app/fedilab/android/MainApplication.java @@ -15,8 +15,11 @@ package app.fedilab.android; * see <http://www.gnu.org/licenses>. */ +import android.app.NotificationChannel; +import android.app.NotificationManager; import android.content.Context; import android.content.SharedPreferences; +import android.os.Build; import android.os.StrictMode; import android.webkit.WebView; @@ -26,6 +29,9 @@ import androidx.preference.PreferenceManager; import com.google.android.material.color.DynamicColors; +import net.gotev.uploadservice.UploadServiceConfig; +import net.gotev.uploadservice.observer.request.GlobalRequestObserver; + import org.acra.ACRA; import org.acra.ReportField; import org.acra.config.CoreConfigurationBuilder; @@ -33,24 +39,21 @@ import org.acra.config.DialogConfigurationBuilder; import org.acra.config.MailSenderConfigurationBuilder; import org.acra.data.StringFormat; +import java.util.Objects; + import app.fedilab.android.mastodon.helper.ThemeHelper; +import app.fedilab.android.peertube.services.GlobalUploadObserver; import es.dmoral.toasty.Toasty; public class MainApplication extends MultiDexApplication { public static String UPLOAD_CHANNEL_ID = "upload_info_peertube"; - private static MainApplication app; private WebView webView; - public static MainApplication getApp() { - return app; - } - @Override public void onCreate() { super.onCreate(); - app = this; SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(MainApplication.this); try { webView = new WebView(this); @@ -69,6 +72,11 @@ public class MainApplication extends MultiDexApplication { } catch (Exception ignored) { } } + + createNotificationChannel(); + UploadServiceConfig.initialize(MainApplication.this, UPLOAD_CHANNEL_ID, true); + + new GlobalRequestObserver(this, new GlobalUploadObserver()); } @@ -111,4 +119,15 @@ public class MainApplication extends MultiDexApplication { ); } } + + + private void createNotificationChannel() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + NotificationChannel channel = new NotificationChannel(UPLOAD_CHANNEL_ID, + getString(R.string.notification_channel_name), + NotificationManager.IMPORTANCE_LOW); + channel.setSound(null, null); + ((NotificationManager) Objects.requireNonNull(getSystemService(Context.NOTIFICATION_SERVICE))).createNotificationChannel(channel); + } + } } diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/BaseActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/BaseActivity.java index 33202d0a4..9b62c2cf2 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/BaseActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/BaseActivity.java @@ -33,6 +33,10 @@ import androidx.preference.PreferenceManager; import com.vanniktech.emoji.EmojiManager; import com.vanniktech.emoji.one.EmojiOneProvider; +import org.conscrypt.Conscrypt; + +import java.security.Security; + import app.fedilab.android.R; import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.ThemeHelper; @@ -44,14 +48,24 @@ public class BaseActivity extends AppCompatActivity { public static int currentThemeId; static { - Helper.installProvider(); EmojiManager.install(new EmojiOneProvider()); } @Override protected void onCreate(@Nullable Bundle savedInstanceState) { - + boolean patch_provider = true; final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this); + try { + patch_provider = sharedpreferences.getBoolean(Helper.SET_SECURITY_PROVIDER, true); + } catch (Exception ignored) { + } + if (patch_provider) { + try { + Security.insertProviderAt(Conscrypt.newProvider(), 1); + } catch (Exception ignored) { + } + } + String currentTheme = sharedpreferences.getString(getString(R.string.SET_THEME_BASE), getString(R.string.SET_DEFAULT_THEME)); //Default automatic switch if (currentTheme.equals(getString(R.string.SET_DEFAULT_THEME))) { diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/BaseAlertDialogActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/BaseAlertDialogActivity.java index 1ab5c897f..ea8f0b701 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/BaseAlertDialogActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/BaseAlertDialogActivity.java @@ -33,6 +33,10 @@ import androidx.preference.PreferenceManager; import com.vanniktech.emoji.EmojiManager; import com.vanniktech.emoji.one.EmojiOneProvider; +import org.conscrypt.Conscrypt; + +import java.security.Security; + import app.fedilab.android.R; import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.ThemeHelper; @@ -42,14 +46,24 @@ import app.fedilab.android.mastodon.helper.ThemeHelper; public class BaseAlertDialogActivity extends AppCompatActivity { static { - Helper.installProvider(); EmojiManager.install(new EmojiOneProvider()); } @Override protected void onCreate(@Nullable Bundle savedInstanceState) { - final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this); + boolean patch_provider = true; + try { + patch_provider = sharedpreferences.getBoolean(Helper.SET_SECURITY_PROVIDER, true); + } catch (Exception ignored) { + } + if (patch_provider) { + try { + Security.insertProviderAt(Conscrypt.newProvider(), 1); + } catch (Exception ignored) { + } + } + String currentTheme = sharedpreferences.getString(getString(R.string.SET_THEME_BASE), getString(R.string.SET_DEFAULT_THEME)); //Default automatic switch if (currentTheme.equals(getString(R.string.SET_DEFAULT_THEME))) { diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/BaseBarActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/BaseBarActivity.java index cd70b928c..900ed0715 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/BaseBarActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/BaseBarActivity.java @@ -33,6 +33,10 @@ import androidx.preference.PreferenceManager; import com.vanniktech.emoji.EmojiManager; import com.vanniktech.emoji.one.EmojiOneProvider; +import org.conscrypt.Conscrypt; + +import java.security.Security; + import app.fedilab.android.R; import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.ThemeHelper; @@ -42,13 +46,23 @@ import app.fedilab.android.mastodon.helper.ThemeHelper; public class BaseBarActivity extends AppCompatActivity { static { - Helper.installProvider(); EmojiManager.install(new EmojiOneProvider()); } @Override protected void onCreate(@Nullable Bundle savedInstanceState) { final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this); + boolean patch_provider = true; + try { + patch_provider = sharedpreferences.getBoolean(Helper.SET_SECURITY_PROVIDER, true); + } catch (Exception ignored) { + } + if (patch_provider) { + try { + Security.insertProviderAt(Conscrypt.newProvider(), 1); + } catch (Exception ignored) { + } + } String currentTheme = sharedpreferences.getString(getString(R.string.SET_THEME_BASE), getString(R.string.SET_DEFAULT_THEME)); //Default automatic switch if (currentTheme.equals(getString(R.string.SET_DEFAULT_THEME))) { diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/BaseFragmentActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/BaseFragmentActivity.java index 30e158d24..1edf6ea59 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/BaseFragmentActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/BaseFragmentActivity.java @@ -15,12 +15,20 @@ package app.fedilab.android.mastodon.activities; * see <http://www.gnu.org/licenses>. */ import android.annotation.SuppressLint; +import android.content.SharedPreferences; +import android.os.Bundle; +import androidx.annotation.Nullable; import androidx.fragment.app.FragmentActivity; +import androidx.preference.PreferenceManager; import com.vanniktech.emoji.EmojiManager; import com.vanniktech.emoji.one.EmojiOneProvider; +import org.conscrypt.Conscrypt; + +import java.security.Security; + import app.fedilab.android.mastodon.helper.Helper; @@ -29,9 +37,23 @@ public class BaseFragmentActivity extends FragmentActivity { static { - Helper.installProvider(); EmojiManager.install(new EmojiOneProvider()); } - + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + boolean patch_provider = true; + try { + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this); + patch_provider = sharedpreferences.getBoolean(Helper.SET_SECURITY_PROVIDER, true); + } catch (Exception ignored) { + } + if (patch_provider) { + try { + Security.insertProviderAt(Conscrypt.newProvider(), 1); + } catch (Exception ignored) { + } + } + super.onCreate(savedInstanceState); + } } diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/BaseTransparentActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/BaseTransparentActivity.java index bc1a50874..ba008f518 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/BaseTransparentActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/BaseTransparentActivity.java @@ -33,6 +33,10 @@ import androidx.preference.PreferenceManager; import com.vanniktech.emoji.EmojiManager; import com.vanniktech.emoji.one.EmojiOneProvider; +import org.conscrypt.Conscrypt; + +import java.security.Security; + import app.fedilab.android.R; import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.ThemeHelper; @@ -42,13 +46,23 @@ import app.fedilab.android.mastodon.helper.ThemeHelper; public class BaseTransparentActivity extends AppCompatActivity { static { - Helper.installProvider(); EmojiManager.install(new EmojiOneProvider()); } @Override protected void onCreate(@Nullable Bundle savedInstanceState) { final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this); + boolean patch_provider = true; + try { + patch_provider = sharedpreferences.getBoolean(Helper.SET_SECURITY_PROVIDER, true); + } catch (Exception ignored) { + } + if (patch_provider) { + try { + Security.insertProviderAt(Conscrypt.newProvider(), 1); + } catch (Exception ignored) { + } + } String currentTheme = sharedpreferences.getString(getString(R.string.SET_THEME_BASE), getString(R.string.SET_DEFAULT_THEME)); //Default automatic switch if (currentTheme.equals(getString(R.string.SET_DEFAULT_THEME))) { diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java b/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java index 4c56d7a5b..59d4fe994 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java +++ b/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java @@ -104,8 +104,6 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonToken; import com.google.gson.stream.JsonWriter; -import org.conscrypt.Conscrypt; - import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; @@ -120,7 +118,6 @@ import java.net.PasswordAuthentication; import java.net.Proxy; import java.net.URL; import java.nio.charset.StandardCharsets; -import java.security.Security; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -143,7 +140,6 @@ import java.util.regex.Pattern; import app.fedilab.android.BaseMainActivity; import app.fedilab.android.BuildConfig; -import app.fedilab.android.MainApplication; import app.fedilab.android.R; import app.fedilab.android.activities.LoginActivity; import app.fedilab.android.activities.MainActivity; @@ -453,22 +449,7 @@ public class Helper { } } - public static void installProvider() { - boolean patch_provider = true; - try { - Context ctx = MainApplication.getApp(); - SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(ctx); - patch_provider = sharedpreferences.getBoolean(Helper.SET_SECURITY_PROVIDER, true); - } catch (Exception ignored) { - } - if (patch_provider) { - try { - Security.insertProviderAt(Conscrypt.newProvider(), 1); - } catch (Exception ignored) { - } - } - } /*** * Check if the user is connected to Internet diff --git a/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeUploadActivity.java b/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeUploadActivity.java index 31f8cd6ca..4d4c7a4ab 100644 --- a/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeUploadActivity.java +++ b/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeUploadActivity.java @@ -19,6 +19,7 @@ import static app.fedilab.android.peertube.activities.PeertubeMainActivity.userM import static app.fedilab.android.peertube.client.RetrofitPeertubeAPI.DataType.MY_CHANNELS; import static app.fedilab.android.peertube.helper.Helper.peertubeInformation; +import android.annotation.SuppressLint; import android.app.Activity; import android.app.PendingIntent; import android.content.Intent; @@ -333,9 +334,17 @@ public class PeertubeUploadActivity extends BaseBarActivity { }); } + @SuppressLint("UnspecifiedImmutableFlag") UploadNotificationConfig getNotificationConfig(String uploadId) { - PendingIntent clickIntent = PendingIntent.getActivity( - PeertubeUploadActivity.this, 1, new Intent(this, PeertubeEditUploadActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); + PendingIntent clickIntent; + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { + clickIntent = PendingIntent.getActivity( + PeertubeUploadActivity.this, 1, new Intent(this, PeertubeEditUploadActivity.class), PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT); + } else { + clickIntent = PendingIntent.getActivity( + PeertubeUploadActivity.this, 1, new Intent(this, PeertubeEditUploadActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); + + } final boolean autoClear = false; final boolean clearOnAction = true; diff --git a/app/src/main/res/layouts/peertube/layout/activity_sepia_search.xml b/app/src/main/res/layouts/peertube/layout/activity_sepia_search.xml index 2cba29f8c..576663ded 100644 --- a/app/src/main/res/layouts/peertube/layout/activity_sepia_search.xml +++ b/app/src/main/res/layouts/peertube/layout/activity_sepia_search.xml @@ -132,13 +132,13 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/sepia_element_nsfw_label"> - <RadioButton + <com.google.android.material.radiobutton.MaterialRadioButton android:id="@+id/sepia_element_nsfw_yes" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/yes" /> - <RadioButton + <com.google.android.material.radiobutton.MaterialRadioButton android:id="@+id/sepia_element_nsfw_no" android:layout_width="wrap_content" android:layout_height="wrap_content" @@ -169,31 +169,31 @@ android:layout_height="wrap_content" android:orientation="horizontal"> - <RadioButton + <com.google.android.material.radiobutton.MaterialRadioButton android:id="@+id/sepia_element_published_date_any" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/any" /> - <RadioButton + <com.google.android.material.radiobutton.MaterialRadioButton android:id="@+id/sepia_element_published_date_today" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/today" /> - <RadioButton + <com.google.android.material.radiobutton.MaterialRadioButton android:id="@+id/sepia_element_published_date_last_7_days" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/last_7_days" /> - <RadioButton + <com.google.android.material.radiobutton.MaterialRadioButton android:id="@+id/sepia_element_published_date_last_30_days" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/last_30_days" /> - <RadioButton + <com.google.android.material.radiobutton.MaterialRadioButton android:id="@+id/sepia_element_published_date_last_365_days" android:layout_width="wrap_content" android:layout_height="wrap_content" @@ -225,25 +225,25 @@ android:layout_height="wrap_content" android:orientation="horizontal"> - <RadioButton + <com.google.android.material.radiobutton.MaterialRadioButton android:id="@+id/sepia_element_duration_any" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/any" /> - <RadioButton + <com.google.android.material.radiobutton.MaterialRadioButton android:id="@+id/sepia_element_duration_short" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/duration_short" /> - <RadioButton + <com.google.android.material.radiobutton.MaterialRadioButton android:id="@+id/sepia_element_duration_medium" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/duration_medium" /> - <RadioButton + <com.google.android.material.radiobutton.MaterialRadioButton android:id="@+id/sepia_element_duration_long" android:layout_width="wrap_content" android:layout_height="wrap_content" @@ -354,9 +354,9 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/sepia_element_one_of_tags_label" /> - <Button + <com.google.android.material.button.MaterialButton android:id="@+id/apply_filter" - style="@style/Base.Widget.AppCompat.Button.Colored" + style="@style/Widget.Material3.Button.ElevatedButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/apply_filter" |