parent
007d6b85fc
commit
e7a6286fb2
|
@ -250,7 +250,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
}
|
||||
|
||||
if (account == null) {
|
||||
Helper.logout(BaseMainActivity.this);
|
||||
Helper.logoutCurrentUser(BaseMainActivity.this);
|
||||
Intent myIntent = new Intent(BaseMainActivity.this, LoginActivity.class);
|
||||
startActivity(myIntent);
|
||||
finish();
|
||||
|
@ -933,23 +933,9 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
|
||||
popup.setOnMenuItemClickListener(item -> {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_logout:
|
||||
AlertDialog.Builder dialogBuilderLogout = new AlertDialog.Builder(BaseMainActivity.this, style);
|
||||
dialogBuilderLogout.setMessage(R.string.logout_confirmation);
|
||||
dialogBuilderLogout.setPositiveButton(R.string.action_logout, (dialog, id) -> {
|
||||
Helper.logout(BaseMainActivity.this);
|
||||
Intent myIntent = new Intent(BaseMainActivity.this, LoginActivity.class);
|
||||
startActivity(myIntent);
|
||||
dialog.dismiss();
|
||||
finish();
|
||||
});
|
||||
dialogBuilderLogout.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
|
||||
AlertDialog alertDialogLogout = dialogBuilderLogout.create();
|
||||
alertDialogLogout.show();
|
||||
return true;
|
||||
case R.id.action_logout_account:
|
||||
AlertDialog.Builder dialogBuilderLogoutAccount = new AlertDialog.Builder(BaseMainActivity.this, style);
|
||||
dialogBuilderLogoutAccount.setMessage(R.string.logout_confirmation);
|
||||
dialogBuilderLogoutAccount.setMessage(R.string.logout_account_confirmation);
|
||||
dialogBuilderLogoutAccount.setPositiveButton(R.string.action_logout, (dialog, id) -> {
|
||||
Helper.logoutCurrentUser(BaseMainActivity.this);
|
||||
dialog.dismiss();
|
||||
|
@ -1699,6 +1685,9 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
if (mPageReferenceMap != null)
|
||||
mPageReferenceMap = null;
|
||||
PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean("isMainActivityRunning", false).apply();
|
||||
if( Sqlite.db != null ) {
|
||||
Sqlite.db.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1978,7 +1967,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
public void onUpdateAccountInfo(boolean error) {
|
||||
if (error) {
|
||||
//An error occurred, the user is redirected to the login page
|
||||
Helper.logout(BaseMainActivity.this);
|
||||
Helper.logoutCurrentUser(BaseMainActivity.this);
|
||||
Intent myIntent = new Intent(BaseMainActivity.this, LoginActivity.class);
|
||||
startActivity(myIntent);
|
||||
finish();
|
||||
|
|
|
@ -262,7 +262,6 @@ public class Helper {
|
|||
public static final String CLIENT_NAME_VALUE = "Fedilab";
|
||||
public static final String OAUTH_SCOPES = "read write follow";
|
||||
public static final String OAUTH_SCOPES_ADMIN = "read write follow admin:read admin:write admin";
|
||||
public static final String OAUTH_SCOPES_PIXELFED = "write follow";
|
||||
public static final String OAUTH_SCOPES_PEERTUBE = "user";
|
||||
public static final String PREF_KEY_OAUTH_TOKEN = "oauth_token";
|
||||
|
||||
|
@ -274,7 +273,6 @@ public class Helper {
|
|||
public static final String REDIRECT_CONTENT = "urn:ietf:wg:oauth:2.0:oob";
|
||||
public static final String REDIRECT_CONTENT_WEB = "mastalab://backtomastalab";
|
||||
public static final int EXTERNAL_STORAGE_REQUEST_CODE = 84;
|
||||
public static final int REQ_CODE_SPEECH_INPUT = 132;
|
||||
|
||||
//Thekinrar's API: https://instances.social/api/doc/
|
||||
public static final String THEKINRAR_SECRET_TOKEN = "jGj9gW3z9ptyIpB8CMGhAlTlslcemMV6AgoiImfw3vPP98birAJTHOWiu5ZWfCkLvcaLsFZw9e3Pb7TIwkbIyrj3z6S7r2oE6uy6EFHvls3YtapP8QKNZ980p9RfzTb4";
|
||||
|
@ -297,14 +295,12 @@ public class Helper {
|
|||
public static final String WEBSITE_VALUE = "https://fedilab.app";
|
||||
public static final String SHOW_BATTERY_SAVER_MESSAGE = "show_battery_saver_message";
|
||||
public static final String LAST_NOTIFICATION_MAX_ID = "last_notification_max_id";
|
||||
public static final String LAST_HOMETIMELINE_MAX_ID = "last_hometimeline_max_id";
|
||||
|
||||
public static final String BOOKMARK_ID = "bookmark_id";
|
||||
public static final String BOOKMARK_DATE = "bookmark_date";
|
||||
public static final String HOME_LAST_READ = "home_last_read";
|
||||
public static final String LAST_READ_TOOT_ID = "last_read_toot_id";
|
||||
public static final String LAST_READ_TOOT_DATE = "last_read_toot_date";
|
||||
public static final String LAST_HOMETIMELINE_NOTIFICATION_MAX_ID = "last_hometimeline_notification_max_id";
|
||||
public static final String SHOULD_CONTINUE_STREAMING = "should_continue_streaming";
|
||||
public static final String SHOULD_CONTINUE_STREAMING_HOME = "should_continue_streaming_home";
|
||||
public static final String SHOULD_CONTINUE_STREAMING_FEDERATED = "should_continue_streaming_federated";
|
||||
public static final String SHOULD_CONTINUE_STREAMING_LOCAL = "should_continue_streaming_local";
|
||||
|
@ -322,7 +318,6 @@ public class Helper {
|
|||
public static final int NOTIFICATION_INTENT = 1;
|
||||
public static final int HOME_TIMELINE_INTENT = 2;
|
||||
public static final int BACK_TO_SETTINGS = 3;
|
||||
public static final int CHANGE_USER_INTENT = 4;
|
||||
public static final int ADD_USER_INTENT = 5;
|
||||
public static final int BACKUP_INTENT = 6;
|
||||
public static final int SEARCH_TAG = 7;
|
||||
|
@ -354,7 +349,6 @@ public class Helper {
|
|||
public static final String SET_SHOW_BOOSTS = "set_show_boost";
|
||||
public static final String SET_SHOW_REPLIES = "set_show_replies";
|
||||
public static final String SET_VIDEO_NSFW = "set_video_nsfw";
|
||||
public static final String NEWS_ACCOUNT_ID = "news_account_id";
|
||||
public static final String SET_LIVE_NOTIFICATIONS = "set_live_notifications";
|
||||
public static final String SET_DELAYED_NOTIFICATIONS = "set_delayed_notifications";
|
||||
public static final String SET_DISABLE_GIF = "set_disable_gif";
|
||||
|
@ -460,7 +454,6 @@ public class Helper {
|
|||
public static final String SET_EXPAND_MEDIA = "set_expand_media";
|
||||
public static final String SET_PHOTO_EDITOR = "set_photo_editor";
|
||||
public static final String MAX_UPLOAD_IMG_RETRY_TIMES = "max_upload_img_retry_times";
|
||||
public static final String SET_DISPLAY_FOLLOW_INSTANCE = "set_display_follow_instance";
|
||||
public static final String SET_DISPLAY_NEW_BADGE = "set_display_new_badge";
|
||||
public static final String SET_DISPLAY_BOT_ICON = "set_display_bot_icon";
|
||||
public static final String SET_DISPLAY_CONFIRM = "set_display_confirm";
|
||||
|
@ -471,11 +464,8 @@ public class Helper {
|
|||
public static final String SET_COOKIES = "set_cookies";
|
||||
public static final String SET_FOLDER_RECORD = "set_folder_record";
|
||||
public static final String SET_TOOT_VISIBILITY = "set_toot_visibility";
|
||||
public static final String SET_DISPLAY_DIRECT = "set_display_direct";
|
||||
public static final String SET_DISPLAY_LOCAL = "set_display_local";
|
||||
public static final String SET_DISPLAY_GLOBAL = "set_display_global";
|
||||
public static final String SET_DISPLAY_ART = "set_display_art";
|
||||
public static final String SET_DISPLAY_PEERTUBE = "set_display_peertube";
|
||||
public static final String SET_AUTOMATICALLY_SPLIT_TOOTS = "set_automatically_split_toots";
|
||||
public static final String SET_AUTOMATICALLY_SPLIT_TOOTS_SIZE = "set_automatically_split_toots_size";
|
||||
public static final String SET_TRUNCATE_TOOTS_SIZE = "set_truncate_toots_size";
|
||||
|
@ -497,7 +487,6 @@ public class Helper {
|
|||
//Refresh job
|
||||
public static final int MINUTES_BETWEEN_NOTIFICATIONS_REFRESH = 15;
|
||||
public static final int MINUTES_BETWEEN_BACKUP = 60;
|
||||
public static final int MINUTES_BETWEEN_HOME_TIMELINE = 30;
|
||||
public static final int SPLIT_TOOT_SIZE = 500;
|
||||
|
||||
//Translate wait time
|
||||
|
@ -530,19 +519,18 @@ public class Helper {
|
|||
|
||||
Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
|
||||
public static final Pattern hashtagPattern = Pattern.compile("(#[\\w_A-zÀ-ÿ]+)");
|
||||
public static final Pattern groupPattern = Pattern.compile("(\\![\\w_]+(\\s|$))");
|
||||
public static final Pattern groupPattern = Pattern.compile("(![\\w_]+(\\s|$))");
|
||||
public static final Pattern twitterPattern = Pattern.compile("((@[\\w]+)@twitter\\.com)");
|
||||
public static final Pattern youtubePattern = Pattern.compile("(www\\.|m\\.)?(youtube\\.com|youtu\\.be|youtube-nocookie\\.com)\\/(((?!(\"|'|<)).)*)");
|
||||
public static final Pattern youtubePattern = Pattern.compile("(www\\.|m\\.)?(youtube\\.com|youtu\\.be|youtube-nocookie\\.com)/(((?!([\"'<])).)*)");
|
||||
public static final Pattern nitterPattern = Pattern.compile("(mobile\\.|www\\.)?twitter.com([\\w-/]+)");
|
||||
public static final Pattern xmppPattern = Pattern.compile("xmpp\\:[-a-zA-Z0-9+$&@#\\/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#\\/%=~_|]");
|
||||
public static final Pattern xmppPattern = Pattern.compile("xmpp:[-a-zA-Z0-9+$&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]");
|
||||
//Default values
|
||||
public final static int DEFAULT_VIDEO_WIDTH = 640;
|
||||
public final static int DEFAULT_VIDEO_HEIGHT = 360;
|
||||
public final static int DEFAULT_VIDEO_BITRATE = 450000;
|
||||
private static final Pattern SHORTNAME_PATTERN = Pattern.compile(":( |)([-+\\w]+):");
|
||||
private static final Pattern mentionPattern = Pattern.compile("(@[\\w_]+(\\s|$))");
|
||||
private static final Pattern mentionLongPattern = Pattern.compile("(@[\\w_-]+@[a-z0-9.\\-]+[.][a-z]{2,10})");
|
||||
private static final Pattern mentionSearchPattern = Pattern.compile("(@[\\w_-]+@[a-z0-9.\\-]+|@[\\w_-]+)");
|
||||
|
||||
/*
|
||||
* List from ClearUrls
|
||||
* https://gitlab.com/KevinRoebert/ClearUrls/blob/master/data/data.min.json#L106
|
||||
|
@ -609,23 +597,15 @@ public class Helper {
|
|||
public static String shortnameToUnicode(String input, boolean removeIfUnsupported) {
|
||||
Matcher matcher = SHORTNAME_PATTERN.matcher(input);
|
||||
|
||||
boolean supported = Build.VERSION.SDK_INT >= 16;
|
||||
while (matcher.find()) {
|
||||
String unicode = emoji.get(matcher.group(2));
|
||||
if (unicode == null) {
|
||||
continue;
|
||||
}
|
||||
if (supported) {
|
||||
if (matcher.group(1).equals(" "))
|
||||
input = input.replace(": " + matcher.group(2) + ":", unicode);
|
||||
else
|
||||
input = input.replace(":" + matcher.group(2) + ":", unicode);
|
||||
} else if (removeIfUnsupported) {
|
||||
if (matcher.group(1).equals(" "))
|
||||
input = input.replace(": " + matcher.group(2) + ":", unicode);
|
||||
else
|
||||
input = input.replace(":" + matcher.group(2) + ":", "");
|
||||
}
|
||||
if (Objects.equals(matcher.group(1), " "))
|
||||
input = input.replace(": " + matcher.group(2) + ":", unicode);
|
||||
else
|
||||
input = input.replace(":" + matcher.group(2) + ":", unicode);
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
@ -691,25 +671,6 @@ public class Helper {
|
|||
return (prefKeyOauthTokenT != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log out the authenticated user by removing its token
|
||||
*
|
||||
* @param context Context
|
||||
*/
|
||||
public static void logout(Context context) {
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
editor.putString(Helper.CLIENT_ID, null);
|
||||
editor.putString(Helper.CLIENT_SECRET, null);
|
||||
editor.putString(Helper.PREF_KEY_ID, null);
|
||||
editor.putBoolean(Helper.PREF_IS_MODERATOR, false);
|
||||
editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, false);
|
||||
editor.putString(Helper.PREF_INSTANCE, null);
|
||||
editor.putString(Helper.ID, null);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
/**
|
||||
* Log out the authenticated user by removing its token
|
||||
*
|
||||
|
@ -718,7 +679,6 @@ public class Helper {
|
|||
public static void logoutCurrentUser(Activity activity) {
|
||||
SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
//Current user
|
||||
|
||||
SQLiteDatabase db = Sqlite.getInstance(activity, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(activity));
|
||||
|
@ -726,6 +686,7 @@ public class Helper {
|
|||
if (account != null) {
|
||||
account.setToken("null");
|
||||
new AccountDAO(activity, db).updateAccount(account);
|
||||
new RemoveAccountAsyncTask(activity, account).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
Account newAccount = new AccountDAO(activity, db).getLastUsedAccount();
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
|
@ -801,7 +762,6 @@ public class Helper {
|
|||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
userLocale = context.getResources().getConfiguration().getLocales().get(0);
|
||||
} else {
|
||||
//noinspection deprecation
|
||||
userLocale = context.getResources().getConfiguration().locale;
|
||||
}
|
||||
String STRING_DATE_FORMAT;
|
||||
|
@ -872,7 +832,6 @@ public class Helper {
|
|||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
userLocale = context.getResources().getConfiguration().getLocales().get(0);
|
||||
} else {
|
||||
//noinspection deprecation
|
||||
userLocale = context.getResources().getConfiguration().locale;
|
||||
}
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", userLocale);
|
||||
|
@ -892,7 +851,6 @@ public class Helper {
|
|||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
userLocale = context.getResources().getConfiguration().getLocales().get(0);
|
||||
} else {
|
||||
//noinspection deprecation
|
||||
userLocale = context.getResources().getConfiguration().locale;
|
||||
}
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", userLocale);
|
||||
|
@ -919,7 +877,6 @@ public class Helper {
|
|||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
userLocale = context.getResources().getConfiguration().getLocales().get(0);
|
||||
} else {
|
||||
//noinspection deprecation
|
||||
userLocale = context.getResources().getConfiguration().locale;
|
||||
}
|
||||
|
||||
|
@ -938,22 +895,19 @@ public class Helper {
|
|||
*/
|
||||
|
||||
public static void absoluteDateTimeReveal(final Context context, final TextView tvDate, final Date date) {
|
||||
tvDate.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
tvDate.setOnClickListener(v -> {
|
||||
|
||||
tvDate.setText(Helper.dateDiffFull(date));
|
||||
tvDate.setText(Helper.dateDiffFull(date));
|
||||
|
||||
new CountDownTimer((5 * 1000), 1000) {
|
||||
new CountDownTimer((5 * 1000), 1000) {
|
||||
|
||||
public void onTick(long millisUntilFinished) {
|
||||
}
|
||||
public void onTick(long millisUntilFinished) {
|
||||
}
|
||||
|
||||
public void onFinish() {
|
||||
tvDate.setText(Helper.dateDiff(context, date));
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
public void onFinish() {
|
||||
tvDate.setText(Helper.dateDiff(context, date));
|
||||
}
|
||||
}.start();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1200,9 +1154,6 @@ public class Helper {
|
|||
return type;
|
||||
}
|
||||
|
||||
public static boolean isNumeric(String str) {
|
||||
return str.matches("-?\\d+(\\.\\d+)?");
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends notification with intent
|
||||
|
@ -1217,19 +1168,7 @@ public class Helper {
|
|||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
// prepare intent which is triggered if the user click on the notification
|
||||
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
|
||||
/*String val;
|
||||
if( isNumeric(account.getId())){
|
||||
val = account.getId();
|
||||
}else{
|
||||
int count = 0;
|
||||
for (int i = 0; i < account.getId().length(); ++i) {
|
||||
count += (int)account.getId().charAt(i);
|
||||
}
|
||||
val = String.valueOf(count);
|
||||
}*/
|
||||
|
||||
int notificationId = (int) System.currentTimeMillis();
|
||||
|
||||
PendingIntent pIntent = PendingIntent.getActivity(context, notificationId, intent, PendingIntent.FLAG_ONE_SHOT);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
||||
|
@ -2179,7 +2118,7 @@ public class Helper {
|
|||
|
||||
}
|
||||
if (account == null) {
|
||||
Helper.logout(activity);
|
||||
Helper.logoutCurrentUser(activity);
|
||||
Intent myIntent = new Intent(activity, LoginActivity.class);
|
||||
Toasty.error(activity, activity.getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
||||
activity.startActivity(myIntent);
|
||||
|
|
|
@ -41,8 +41,4 @@
|
|||
android:id="@+id/action_logout_account"
|
||||
android:title="@string/action_logout_account"
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/action_logout"
|
||||
android:title="@string/action_logout"
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
||||
|
|
|
@ -85,6 +85,7 @@
|
|||
<string name="no_emoji">The app did not collect custom emojis for the moment.</string>
|
||||
<string name="live_notif">Live notifications</string>
|
||||
<string name="logout_confirmation">Are you sure you want to logout?</string>
|
||||
<string name="logout_account_confirmation">Are you sure you want to logout this account?</string>
|
||||
<!-- Status -->
|
||||
<string name="no_status">No toot to display</string>
|
||||
<string name="no_stories">No stories to display</string>
|
||||
|
|
Loading…
Reference in New Issue