diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2c6d8ed9..76a88d17 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -24,6 +24,7 @@ android:supportsRtl="true" android:theme="@style/AppTheme" tools:replace="android:allowBackup"> + Build.VERSION_CODES.N) { + updateResourcesLocale(context, locale) + } else updateResourcesLocaleLegacy(context, locale) + } + + private fun updateResourcesLocale(context: Context, locale: Locale): Context = + context.createConfigurationContext( + Configuration(context.resources.configuration) + .apply { setLocale(locale) } + ) + + @SuppressWarnings("deprecation") + private fun updateResourcesLocaleLegacy(context: Context, locale: Locale): Context { + val resources: Resources = context.resources + val configuration: Configuration = resources.configuration + configuration.locale = locale + resources.updateConfiguration(configuration, resources.displayMetrics) + return context + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/h/pixeldroid/FollowsActivity.kt b/app/src/main/java/com/h/pixeldroid/FollowsActivity.kt index 7ea31459..b12a5fc4 100644 --- a/app/src/main/java/com/h/pixeldroid/FollowsActivity.kt +++ b/app/src/main/java/com/h/pixeldroid/FollowsActivity.kt @@ -11,7 +11,7 @@ import com.h.pixeldroid.objects.Account.Companion.FOLLOWERS_TAG import javax.inject.Inject -class FollowsActivity : AppCompatActivity() { +class FollowsActivity : BaseActivity() { private var followsFragment = AccountListFragment() @Inject lateinit var db: AppDatabase diff --git a/app/src/main/java/com/h/pixeldroid/LicenseActivity.kt b/app/src/main/java/com/h/pixeldroid/LicenseActivity.kt index 6900d2dc..ead11b16 100644 --- a/app/src/main/java/com/h/pixeldroid/LicenseActivity.kt +++ b/app/src/main/java/com/h/pixeldroid/LicenseActivity.kt @@ -5,7 +5,7 @@ import androidx.appcompat.app.AppCompatActivity import kotlinx.android.synthetic.main.activity_licenses.* -class LicenseActivity : AppCompatActivity() { +class LicenseActivity : BaseActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_licenses) diff --git a/app/src/main/java/com/h/pixeldroid/LoginActivity.kt b/app/src/main/java/com/h/pixeldroid/LoginActivity.kt index af3cd7f3..f5d17ac2 100644 --- a/app/src/main/java/com/h/pixeldroid/LoginActivity.kt +++ b/app/src/main/java/com/h/pixeldroid/LoginActivity.kt @@ -48,7 +48,7 @@ since they do not depend on each other) */ -class LoginActivity : AppCompatActivity() { +class LoginActivity : BaseActivity() { companion object { private const val PACKAGE_ID = BuildConfig.APPLICATION_ID diff --git a/app/src/main/java/com/h/pixeldroid/MainActivity.kt b/app/src/main/java/com/h/pixeldroid/MainActivity.kt index e3bf9695..6f181206 100644 --- a/app/src/main/java/com/h/pixeldroid/MainActivity.kt +++ b/app/src/main/java/com/h/pixeldroid/MainActivity.kt @@ -45,7 +45,7 @@ import retrofit2.Response import java.lang.IllegalArgumentException import javax.inject.Inject -class MainActivity : AppCompatActivity() { +class MainActivity : BaseActivity() { @Inject lateinit var db: AppDatabase diff --git a/app/src/main/java/com/h/pixeldroid/PhotoEditActivity.kt b/app/src/main/java/com/h/pixeldroid/PhotoEditActivity.kt index 7ba550e8..2d1d4834 100644 --- a/app/src/main/java/com/h/pixeldroid/PhotoEditActivity.kt +++ b/app/src/main/java/com/h/pixeldroid/PhotoEditActivity.kt @@ -59,7 +59,7 @@ private const val REQUEST_CODE_PERMISSIONS_SEND_PHOTO = 7 private val REQUIRED_PERMISSIONS = arrayOf(android.Manifest.permission.READ_EXTERNAL_STORAGE, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) -class PhotoEditActivity : AppCompatActivity(), FilterListFragmentListener, EditImageFragmentListener { +class PhotoEditActivity : BaseActivity(), FilterListFragmentListener, EditImageFragmentListener { internal var saving: Boolean = false private val BITMAP_CONFIG = Bitmap.Config.ARGB_8888 diff --git a/app/src/main/java/com/h/pixeldroid/PostActivity.kt b/app/src/main/java/com/h/pixeldroid/PostActivity.kt index f83d3c4d..8a209c93 100644 --- a/app/src/main/java/com/h/pixeldroid/PostActivity.kt +++ b/app/src/main/java/com/h/pixeldroid/PostActivity.kt @@ -20,7 +20,7 @@ import retrofit2.Callback import retrofit2.Response import javax.inject.Inject -class PostActivity : AppCompatActivity() { +class PostActivity : BaseActivity() { private lateinit var postFragment : PostFragment lateinit var domain : String private lateinit var accessToken : String diff --git a/app/src/main/java/com/h/pixeldroid/PostCreationActivity.kt b/app/src/main/java/com/h/pixeldroid/PostCreationActivity.kt index 294fa2c1..c2a2d216 100644 --- a/app/src/main/java/com/h/pixeldroid/PostCreationActivity.kt +++ b/app/src/main/java/com/h/pixeldroid/PostCreationActivity.kt @@ -41,7 +41,7 @@ private val TAG = "Post Creation Activity" private val MORE_PICTURES_REQUEST_CODE = 0xffff -class PostCreationActivity : AppCompatActivity(), PostCreationListener { +class PostCreationActivity : BaseActivity(), PostCreationListener { private lateinit var recycler : RecyclerView private lateinit var adapter : PostCreationAdapter diff --git a/app/src/main/java/com/h/pixeldroid/ProfileActivity.kt b/app/src/main/java/com/h/pixeldroid/ProfileActivity.kt index ac186b68..ec8d4922 100644 --- a/app/src/main/java/com/h/pixeldroid/ProfileActivity.kt +++ b/app/src/main/java/com/h/pixeldroid/ProfileActivity.kt @@ -29,7 +29,7 @@ import retrofit2.Callback import retrofit2.Response import javax.inject.Inject -class ProfileActivity : AppCompatActivity() { +class ProfileActivity : BaseActivity() { private lateinit var pixelfedAPI : PixelfedAPI private lateinit var adapter : ProfilePostsRecyclerViewAdapter private lateinit var recycler : RecyclerView diff --git a/app/src/main/java/com/h/pixeldroid/ReportActivity.kt b/app/src/main/java/com/h/pixeldroid/ReportActivity.kt index 461e5a19..ae66bcb7 100644 --- a/app/src/main/java/com/h/pixeldroid/ReportActivity.kt +++ b/app/src/main/java/com/h/pixeldroid/ReportActivity.kt @@ -14,7 +14,7 @@ import retrofit2.Callback import retrofit2.Response import javax.inject.Inject -class ReportActivity : AppCompatActivity() { +class ReportActivity : BaseActivity() { @Inject lateinit var db: AppDatabase diff --git a/app/src/main/java/com/h/pixeldroid/SearchActivity.kt b/app/src/main/java/com/h/pixeldroid/SearchActivity.kt index ca8d937a..99bb7e11 100644 --- a/app/src/main/java/com/h/pixeldroid/SearchActivity.kt +++ b/app/src/main/java/com/h/pixeldroid/SearchActivity.kt @@ -15,7 +15,7 @@ import com.h.pixeldroid.fragments.feeds.uncachedFeeds.search.SearchHashtagFragme import com.h.pixeldroid.fragments.feeds.uncachedFeeds.search.SearchPostsFragment import com.h.pixeldroid.objects.Results -class SearchActivity : AppCompatActivity() { +class SearchActivity : BaseActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/java/com/h/pixeldroid/SettingsActivity.kt b/app/src/main/java/com/h/pixeldroid/SettingsActivity.kt index 03914ce8..9f3a226c 100644 --- a/app/src/main/java/com/h/pixeldroid/SettingsActivity.kt +++ b/app/src/main/java/com/h/pixeldroid/SettingsActivity.kt @@ -3,14 +3,12 @@ package com.h.pixeldroid import android.content.Intent import android.content.SharedPreferences import android.os.Bundle -import androidx.appcompat.app.AppCompatActivity -import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceManager import com.h.pixeldroid.utils.ThemeUtils.Companion.setThemeFromPreferences -class SettingsActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceChangeListener { - private var restartActivitiesOnExit = false +class SettingsActivity : BaseActivity(), SharedPreferences.OnSharedPreferenceChangeListener { + private var restartMainOnExit = false override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -21,11 +19,8 @@ class SettingsActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferen .replace(R.id.settings, SettingsFragment()) .commit() supportActionBar?.setDisplayHomeAsUpEnabled(true) - } - private fun restartCurrentActivity() { - intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK - super.startActivity(intent) + restartMainOnExit = intent.getBooleanExtra("restartMain", false) } override fun onResume() { @@ -42,16 +37,43 @@ class SettingsActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferen ) } + override fun onBackPressed() { + // If a setting (for example language or theme) was changed, the main activity should be + // started without history so that the change is applied to the whole back stack + if (restartMainOnExit) { + val intent = Intent(this, MainActivity::class.java) + intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK + super.startActivity(intent) + } else { + super.onBackPressed() + } + } override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) { when (key) { - "theme" -> setThemeFromPreferences(sharedPreferences, resources) + "theme" -> { + setThemeFromPreferences(sharedPreferences, resources) + recreateWithRestartStatus() + } + "language" -> { + recreateWithRestartStatus() + } } - - restartActivitiesOnExit = true - restartCurrentActivity() } - class SettingsFragment : PreferenceFragmentCompat() { + /** + * Mark main activity to be changed and recreate the current one + */ + private fun recreateWithRestartStatus() { + intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK + val savedInstanceState = Bundle().apply { + putBoolean("restartMain", true) + } + intent.putExtras(savedInstanceState) + super.startActivity(intent) + finish() + } + + class SettingsFragment : PreferenceFragmentCompat() { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { setPreferencesFromResource(R.xml.root_preferences, rootKey) } diff --git a/app/src/main/java/com/h/pixeldroid/di/ApplicationComponent.kt b/app/src/main/java/com/h/pixeldroid/di/ApplicationComponent.kt index 6760cbc0..0dbf6095 100644 --- a/app/src/main/java/com/h/pixeldroid/di/ApplicationComponent.kt +++ b/app/src/main/java/com/h/pixeldroid/di/ApplicationComponent.kt @@ -23,10 +23,7 @@ interface ApplicationComponent { fun inject(activity: ProfileActivity?) fun inject(mainActivity: MainActivity?) fun inject(activity: ReportActivity?) - fun inject(fragment: PostFragment) - fun inject(fragment: SearchDiscoverFragment) - fun inject(fragment: NotificationsFragment) fun inject(feedFragment: BaseFragment) fun inject(followsActivity: FollowsActivity) diff --git a/app/src/main/java/com/h/pixeldroid/fragments/SearchDiscoverFragment.kt b/app/src/main/java/com/h/pixeldroid/fragments/SearchDiscoverFragment.kt index b004528a..2193937a 100644 --- a/app/src/main/java/com/h/pixeldroid/fragments/SearchDiscoverFragment.kt +++ b/app/src/main/java/com/h/pixeldroid/fragments/SearchDiscoverFragment.kt @@ -43,7 +43,7 @@ import javax.inject.Inject * This fragment lets you search and use Pixelfed's Discover feature */ -class SearchDiscoverFragment : Fragment() { +class SearchDiscoverFragment : BaseFragment() { private lateinit var api: PixelfedAPI private lateinit var recycler : RecyclerView private lateinit var adapter : DiscoverRecyclerViewAdapter @@ -51,14 +51,6 @@ class SearchDiscoverFragment : Fragment() { private lateinit var discoverProgressBar: ProgressBar private lateinit var discoverRefreshLayout: SwipeRefreshLayout - @Inject - lateinit var db: AppDatabase - - @Inject - lateinit var apiHolder: PixelfedAPIHolder - - - override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? @@ -66,9 +58,6 @@ class SearchDiscoverFragment : Fragment() { val view = inflater.inflate(R.layout.fragment_search, container, false) val search = view.findViewById(R.id.search) - (requireActivity().application as Pixeldroid).getAppComponent().inject(this) - - //Configure the search widget (see https://developer.android.com/guide/topics/search/search-dialog#ConfiguringWidget) val searchManager = requireActivity().getSystemService(Context.SEARCH_SERVICE) as SearchManager search.setSearchableInfo(searchManager.getSearchableInfo(requireActivity().componentName)) diff --git a/app/src/main/res/drawable/translate_black_24dp.xml b/app/src/main/res/drawable/translate_black_24dp.xml new file mode 100644 index 00000000..f0e4e67f --- /dev/null +++ b/app/src/main/res/drawable/translate_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index bf6d96a7..183e167a 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -47,7 +47,7 @@ داكن فاتح تم حفظ الصورة بنجاح - افتراضي (يتبع النظام) + افتراضي (يتبع النظام) يجب أن يحتوي الوصف على %1$s حرفًا على الأكثر. تم تحميل المنشور بنجاح فشل في تحميل المنشور diff --git a/app/src/main/res/values-ca/strings.xml b/app/src/main/res/values-ca/strings.xml index 31d271e5..6a311266 100644 --- a/app/src/main/res/values-ca/strings.xml +++ b/app/src/main/res/values-ca/strings.xml @@ -93,7 +93,7 @@ Permís denegat Fosc Clar - Per defecte (seguint el sistema) + Per defecte (seguint el sistema) {gmd_cloud_done} S\'ha completat l\'enviament multimèdia {gmd_cloud_off} L\'enviament multimèdia ha fallat, torna-ho a provar o comprova les condicions de la xarxa Imatge que s\'està publicant diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 56a71187..17e27150 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -41,7 +41,7 @@ Konnte die App nicht mit diesem Server verbinden Konnte die Informationen der Instanz nicht abrufen Fehler beim Hochladen! - Standard (Systemeinstellung) + Standard (Systemeinstellung) Berechtigung verweigert Bild kann nicht gespeichert werden Die Beschreibung darf höchstens %1$s Zeichen enthalten. diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 8599e9b7..078750d2 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -97,7 +97,7 @@ Permiso denegado Oscuro Claro - Por defecto (Sistema) + Por defecto (Sistema) No se pudo recuperar la imagen después del recorte Bien, espera. Procesando imagen, ¡Espera a que termine! diff --git a/app/src/main/res/values-eu/strings.xml b/app/src/main/res/values-eu/strings.xml index 7f16c7a5..e606a78b 100644 --- a/app/src/main/res/values-eu/strings.xml +++ b/app/src/main/res/values-eu/strings.xml @@ -59,7 +59,7 @@ Ezinezkoa irudia gordetzea Iluna Argia - Lehenetsia (Sistemaren lehentsia) + Lehenetsia (Sistemaren lehentsia) Deskribapenik ez Deskribapenak %1$s karaktere izan behar ditu gehienez. Irudia behar bezala gorde da diff --git a/app/src/main/res/values-fa/strings.xml b/app/src/main/res/values-fa/strings.xml index c84bb5a4..f3aadd4b 100644 --- a/app/src/main/res/values-fa/strings.xml +++ b/app/src/main/res/values-fa/strings.xml @@ -45,7 +45,7 @@ ممنوعیت دسترسی نتوانستیم تصویر را ذخیره کنیم توضیحات حداکثر می‌توانند تا %1$s حرف داشته باشند. - پیش‌گزیده (پیروی از سامانه) + پیش‌گزیده (پیروی از سامانه) روشن تاریک بارگذاری مطلب ناموفق بود diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 870a5465..f91c812a 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -51,7 +51,7 @@ Permission refusée Sombre Clair - Par défaut (selon votre système) + Par défaut (selon votre système) Échec du téléversement de la publication Téléversement de la publication avec succès Publié le %1$s diff --git a/app/src/main/res/values-gl/strings.xml b/app/src/main/res/values-gl/strings.xml index a2f8fa59..538a492e 100644 --- a/app/src/main/res/values-gl/strings.xml +++ b/app/src/main/res/values-gl/strings.xml @@ -93,7 +93,7 @@ Permiso denegado Escuro Claro - Por omisión (do sistema) + Por omisión (do sistema) {gmd_cloud_off} Fallou a subida do ficheiro, inténtao outra vez e comproba a conexión Imaxe que se publicou {gmd_cloud_done} Subida do ficheiro completada diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index a814774a..d23c0ae2 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -97,7 +97,7 @@ {gmd_cloud_off} Caricamento dei contenuti non riuscito, riprovare o verificare le condizioni della rete Impossibile visualizzare il tasto segui Impossibile ottenere lo stato segui - Predefinito (Segue il sistema) + Predefinito (Segue il sistema) Impossibile recuperare l\'immagine dopo il ritaglio Ok, aspetta. Elaborando ancora l\'immagine, attendi che finisca prima! diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 2d215bed..b2671319 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -97,7 +97,7 @@ 権限がありません ダーク ライト - デフォルト(システム設定) + デフォルト(システム設定) お待ちください。 画像を処理しています。しばらくお待ちください。 ここには何もありません! diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 8ae27593..fbb711ee 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -74,7 +74,7 @@ Kon post niet uploaden Kon afbeelding niet opslaan Toestemming geweigerd - Standaard (systeem instelling) + Standaard (systeem instelling) Kon instance-informatie niet ophalen %1$s Vind-ik-leuks Fout bij het uploaden: slecht verzoekformaat diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index d46b03aa..38f26b01 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -58,7 +58,7 @@ Nie udało się zarejestrować aplikacji na tym serwerze Nie udało się pobrać informacji o instancji To chyba nie jest instancja Pixelfed. Aplikacja może zachowywać się nieprzewidywalnie. - Systemowy + Systemowy %1$s obserwujących %1$s polubień Co to jest instancja\? diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index af3350af..6f6e0f25 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -74,7 +74,7 @@ Недостаточно прав Тёмная Светлая - По умолчанию (как в системе) + По умолчанию (как в системе) Не удалось получить статус подписки Не удалось подписаться Это действие запрещено diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 905ac5ec..90c0524b 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -97,7 +97,7 @@ Åtkomst nekas Mörkt Ljust - Standard (Följer systemet) + Standard (Följer systemet) Det finns inget här! Kunde inte hämta bilden efter beskärning OK, vänta på det. diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 65345dfc..65974179 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -95,7 +95,7 @@ 图片成功保存 无法保存图像 没有权限 - 默认(跟随系统设置) + 默认(跟随系统设置) 浅色 深色 这里什么也没有! diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 8b34eeb0..74a364f5 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -6,8 +6,53 @@ - @string/default_theme + @string/default_system @string/light_theme @string/dark_theme + + + + @string/default_system + العربية + বাংলা (বাংলাদেশ) + Català + Deutsch + Esperanto + Euskara + فارسی + Français + Gaeilge + Italiano + 日本語 + Nederlands + Polski + Português (Brasil) + Русский + Svenska + Українська + 中文(简体) + + + + default + ar + bn-bd + ca + de + es + eu + fa + fr + gl + it + ja + nl + pl + pt-br + ru + sv + uk + zh-CN + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a358ec97..1d076f1d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -16,7 +16,7 @@ Application Theme Theme - Default (Follows system) + Default (Follows system) Light Dark %1$s followed you @@ -143,6 +143,7 @@ OK Delete this post? Cancel + Language \ No newline at end of file diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml index 282ca030..8bf34564 100644 --- a/app/src/main/res/xml/root_preferences.xml +++ b/app/src/main/res/xml/root_preferences.xml @@ -18,4 +18,13 @@ android:targetPackage="com.h.pixeldroid" android:targetClass="com.h.pixeldroid.AboutActivity"/> + +