2020-04-26 15:36:33 +02:00
|
|
|
package org.mian.gitnex.activities;
|
|
|
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.TextView;
|
2022-08-07 21:34:02 +02:00
|
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
2022-09-21 07:43:00 +02:00
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.Locale;
|
2020-04-26 15:36:33 +02:00
|
|
|
import org.mian.gitnex.R;
|
2021-01-26 16:10:31 +01:00
|
|
|
import org.mian.gitnex.databinding.ActivitySettingsTranslationBinding;
|
Don't use TinyDB as cache (#1034)
Do not use TinyDB as a cache or a way to send data between activities.
### How is this working
Instead of saving everything into the TinyDB, I created three `Context`s (a `RepositoryContext`, an `IssueContext` and an `AccountContext`). All are used to store things like API or database values/models and additional data, e.g. the `RepositoryContext` also contains information about the current filter state of a repository (issues, pull requests, releases/tags and milestones). These are sent using `Intent`s and `Bundle`s between activities and fragments. Changing a field (e.g. filter state) in any fragment changes it also for the whole repository (or at least it should do so).
Due to the size of the changes (after https://codeberg.org/gitnex/GitNex/commit/c9172f85efafd9f25739fdd8385e1904b711ea41, Git says `154 files changed, 3318 insertions(+), 3835 deletions(-)`) **I highly recommend you to create a beta/pre release before releasing a stable version**.
Additional changes:
* after logging out, the account remains in the account list (with a note) and you can log in again (you can't switch to this account)
* repositories and organizations are clickable on user profiles
* deleted two unused classes
Once finished, hopefully
* closes #354
* replaces #897
* fixes #947
* closes #1001
* closes #1015
* marks #876 and #578 as `Wontfix` since they are not necessary at this point
* and all the other TinyDB issues
Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1034
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-03-13 03:59:13 +01:00
|
|
|
import org.mian.gitnex.fragments.SettingsFragment;
|
2021-12-17 20:56:12 +01:00
|
|
|
import org.mian.gitnex.helpers.AppUtil;
|
2020-04-26 15:36:33 +02:00
|
|
|
import org.mian.gitnex.helpers.Toasty;
|
|
|
|
|
|
|
|
/**
|
2022-07-29 14:08:44 +02:00
|
|
|
* @author M M Arif
|
2020-04-26 15:36:33 +02:00
|
|
|
*/
|
|
|
|
public class SettingsTranslationActivity extends BaseActivity {
|
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
private static int langSelectedChoice = 0;
|
2020-04-26 15:36:33 +02:00
|
|
|
private View.OnClickListener onClickListener;
|
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
private static String getLanguageDisplayName(String langCode) {
|
|
|
|
Locale english = new Locale("en");
|
|
|
|
Locale translated = new Locale(langCode);
|
2022-09-21 07:43:00 +02:00
|
|
|
return String.format(
|
|
|
|
"%s (%s)",
|
|
|
|
translated.getDisplayName(translated), translated.getDisplayName(english));
|
2022-08-15 16:26:02 +02:00
|
|
|
}
|
2020-04-26 15:36:33 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
2021-05-29 18:21:48 +02:00
|
|
|
LinkedHashMap<String, String> langs = new LinkedHashMap<>();
|
|
|
|
langs.put("", getString(R.string.settingsLanguageSystem));
|
2022-09-21 07:43:00 +02:00
|
|
|
for (String langCode : getResources().getStringArray(R.array.languages)) {
|
2021-05-29 18:21:48 +02:00
|
|
|
langs.put(langCode, getLanguageDisplayName(langCode));
|
|
|
|
}
|
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
ActivitySettingsTranslationBinding activitySettingsTranslationBinding =
|
|
|
|
ActivitySettingsTranslationBinding.inflate(getLayoutInflater());
|
2021-01-26 18:43:25 +01:00
|
|
|
setContentView(activitySettingsTranslationBinding.getRoot());
|
2021-01-26 16:10:31 +01:00
|
|
|
|
|
|
|
ImageView closeActivity = activitySettingsTranslationBinding.close;
|
2020-04-26 15:36:33 +02:00
|
|
|
|
|
|
|
initCloseListener();
|
|
|
|
closeActivity.setOnClickListener(onClickListener);
|
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
final TextView tvLanguageSelected =
|
|
|
|
activitySettingsTranslationBinding.tvLanguageSelected; // setter for en, fr
|
2021-01-26 16:10:31 +01:00
|
|
|
TextView helpTranslate = activitySettingsTranslationBinding.helpTranslate;
|
2020-04-26 15:36:33 +02:00
|
|
|
|
2021-01-26 16:10:31 +01:00
|
|
|
LinearLayout langFrame = activitySettingsTranslationBinding.langFrame;
|
2020-04-26 15:36:33 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
helpTranslate.setOnClickListener(
|
|
|
|
v12 -> {
|
|
|
|
AppUtil.openUrlInBrowser(this, getResources().getString(R.string.crowdInLink));
|
|
|
|
});
|
2020-04-26 15:36:33 +02:00
|
|
|
|
2021-05-29 18:21:48 +02:00
|
|
|
langSelectedChoice = tinyDB.getInt("langId");
|
2022-09-21 07:43:00 +02:00
|
|
|
tvLanguageSelected.setText(
|
|
|
|
langs.get(langs.keySet().toArray(new String[0])[langSelectedChoice]));
|
2020-04-26 15:36:33 +02:00
|
|
|
|
|
|
|
// language dialog
|
2022-09-21 07:43:00 +02:00
|
|
|
langFrame.setOnClickListener(
|
|
|
|
view -> {
|
|
|
|
MaterialAlertDialogBuilder materialAlertDialogBuilder =
|
|
|
|
new MaterialAlertDialogBuilder(ctx)
|
|
|
|
.setTitle(R.string.settingsLanguageSelectorDialogTitle)
|
|
|
|
.setCancelable(langSelectedChoice != -1)
|
|
|
|
.setNeutralButton(getString(R.string.cancelButton), null)
|
|
|
|
.setSingleChoiceItems(
|
|
|
|
langs.values().toArray(new String[0]),
|
|
|
|
langSelectedChoice,
|
|
|
|
(dialogInterface, i) -> {
|
|
|
|
String selectedLanguage =
|
|
|
|
langs.keySet().toArray(new String[0])[i];
|
|
|
|
tinyDB.putInt("langId", i);
|
|
|
|
tinyDB.putString("locale", selectedLanguage);
|
|
|
|
|
|
|
|
SettingsFragment.refreshParent = true;
|
|
|
|
this.overridePendingTransition(0, 0);
|
|
|
|
dialogInterface.dismiss();
|
|
|
|
Toasty.success(
|
|
|
|
appCtx,
|
|
|
|
getResources()
|
|
|
|
.getString(R.string.settingsSave));
|
|
|
|
this.recreate();
|
|
|
|
});
|
|
|
|
|
|
|
|
materialAlertDialogBuilder.create().show();
|
2022-08-07 21:34:02 +02:00
|
|
|
});
|
2020-04-26 15:36:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void initCloseListener() {
|
2020-09-13 13:11:55 +02:00
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
onClickListener = view -> finish();
|
2020-04-26 15:36:33 +02:00
|
|
|
}
|
|
|
|
}
|