summaryrefslogtreecommitdiffstats
path: root/app/src/main/java
diff options
context:
space:
mode:
authortom79 <tschneider.ac@gmail.com>2020-04-16 14:34:45 +0200
committertom79 <tschneider.ac@gmail.com>2020-04-16 14:34:45 +0200
commitebc554b0f5c5d64e162f5b345257375f44af5a00 (patch)
treed1aa0f13ee054659876c4ba7bfc8e5a01ed7fed6 /app/src/main/java
parent255834256104be51f9155a2ca0178c122ce08b61 (diff)
Fix notification issue
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/app/fedilab/android/activities/EditProfileActivity.java2
-rw-r--r--app/src/main/java/app/fedilab/android/activities/TootActivity.java2
-rw-r--r--app/src/main/java/app/fedilab/android/asynctasks/RetrieveFeedsAsyncTask.java4
-rw-r--r--app/src/main/java/app/fedilab/android/asynctasks/SyncBookmarksAsyncTask.java6
-rw-r--r--app/src/main/java/app/fedilab/android/client/API.java36
-rw-r--r--app/src/main/java/app/fedilab/android/client/Entities/Account.java1
-rw-r--r--app/src/main/java/app/fedilab/android/drawers/NotificationsListAdapter.java2
-rw-r--r--app/src/main/java/app/fedilab/android/drawers/ReactionAdapter.java6
-rw-r--r--app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java12
-rw-r--r--app/src/main/java/app/fedilab/android/fragments/DisplayFiltersFragment.java207
-rw-r--r--app/src/main/java/app/fedilab/android/helper/Helper.java2
-rw-r--r--app/src/main/java/app/fedilab/android/helper/MastalabAutoCompleteTextView.java83
-rw-r--r--app/src/main/java/app/fedilab/android/services/LiveNotificationService.java3
-rw-r--r--app/src/main/java/app/fedilab/android/sqlite/TimelineCacheDAO.java6
14 files changed, 182 insertions, 190 deletions
diff --git a/app/src/main/java/app/fedilab/android/activities/EditProfileActivity.java b/app/src/main/java/app/fedilab/android/activities/EditProfileActivity.java
index 556eef31e..48449b116 100644
--- a/app/src/main/java/app/fedilab/android/activities/EditProfileActivity.java
+++ b/app/src/main/java/app/fedilab/android/activities/EditProfileActivity.java
@@ -359,7 +359,7 @@ public class EditProfileActivity extends BaseActivity implements OnRetrieveAccou
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
set_profile_save.setOnClickListener(v -> {
- if (set_profile_name.getText() != null )
+ if (set_profile_name.getText() != null)
profile_username = set_profile_name.getText().toString().trim();
else
profile_username = "";
diff --git a/app/src/main/java/app/fedilab/android/activities/TootActivity.java b/app/src/main/java/app/fedilab/android/activities/TootActivity.java
index b83648fb2..569ea9867 100644
--- a/app/src/main/java/app/fedilab/android/activities/TootActivity.java
+++ b/app/src/main/java/app/fedilab/android/activities/TootActivity.java
@@ -809,7 +809,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate,
SharedPreferences sharedpreferences1 = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
boolean photo_editor = sharedpreferences1.getBoolean(Helper.SET_PHOTO_EDITOR, true);
- if( inputContentInfo != null ) {
+ if (inputContentInfo != null) {
Uri uri = inputContentInfo.getContentUri();
String filename = Helper.getFileName(TootActivity.this, uri);
ContentResolver cr = getContentResolver();
diff --git a/app/src/main/java/app/fedilab/android/asynctasks/RetrieveFeedsAsyncTask.java b/app/src/main/java/app/fedilab/android/asynctasks/RetrieveFeedsAsyncTask.java
index 334d243b8..ae776c9ca 100644
--- a/app/src/main/java/app/fedilab/android/asynctasks/RetrieveFeedsAsyncTask.java
+++ b/app/src/main/java/app/fedilab/android/asynctasks/RetrieveFeedsAsyncTask.java
@@ -367,13 +367,13 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
apiResponse = new APIResponse();
db = Sqlite.getInstance(contextReference.get().getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
List<app.fedilab.android.client.Entities.Status> statuses = new StatusCacheDAO(contextReference.get(), db).getAllStatus(StatusCacheDAO.BOOKMARK_CACHE);
- if( statuses != null ) {
+ if (statuses != null) {
for (app.fedilab.android.client.Entities.Status status : statuses) {
app.fedilab.android.client.Entities.Status.fillSpan(contextReference.get(), status);
app.fedilab.android.client.Entities.Status.makeEmojiPoll(contextReference.get(), status.getReblog() != null ? status.getReblog().getPoll() : status.getPoll());
Account.makeAccountNameEmoji(contextReference.get(), status.getReblog() != null ? status.getReblog().getAccount() : status.getAccount());
}
- }else {
+ } else {
statuses = new ArrayList<>();
}
apiResponse.setStatuses(statuses);
diff --git a/app/src/main/java/app/fedilab/android/asynctasks/SyncBookmarksAsyncTask.java b/app/src/main/java/app/fedilab/android/asynctasks/SyncBookmarksAsyncTask.java
index 4437f4ec8..ce64002d9 100644
--- a/app/src/main/java/app/fedilab/android/asynctasks/SyncBookmarksAsyncTask.java
+++ b/app/src/main/java/app/fedilab/android/asynctasks/SyncBookmarksAsyncTask.java
@@ -50,12 +50,14 @@ public class SyncBookmarksAsyncTask extends AsyncTask<Void, Void, Void> {
this.type = type;
this.listener = onSyncBookmarksInterface;
}
+
public SyncBookmarksAsyncTask(Context context, String statusId, OnSyncBookmarksInterface onSyncBookmarksInterface) {
this.contextReference = new WeakReference<>(context);
this.type = sync.REFRESH;
this.statusId = statusId;
this.listener = onSyncBookmarksInterface;
}
+
@Override
protected Void doInBackground(Void... params) {
SQLiteDatabase db = Sqlite.getInstance(contextReference.get().getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
@@ -78,7 +80,7 @@ public class SyncBookmarksAsyncTask extends AsyncTask<Void, Void, Void> {
}
} while (max_id != null);
statusList = new StatusCacheDAO(contextReference.get(), db).getAllStatus(BOOKMARK_CACHE);
- } else if (type == sync.EXPORT){
+ } else if (type == sync.EXPORT) {
List<app.fedilab.android.client.Entities.Status> statuses = new StatusCacheDAO(contextReference.get(), db).getAllStatus(BOOKMARK_CACHE);
if (statuses != null) {
for (app.fedilab.android.client.Entities.Status tmpStatus : statuses) {
@@ -91,7 +93,7 @@ public class SyncBookmarksAsyncTask extends AsyncTask<Void, Void, Void> {
}
}
statusList = new StatusCacheDAO(contextReference.get(), db).getAllStatus(BOOKMARK_CACHE);
- }else {
+ } else {
APIResponse apiResponse = new API(contextReference.get()).getStatusbyIdAndCache(statusId);
app.fedilab.android.client.Entities.Status refreshedStatus = apiResponse.getStatuses().get(0);
new StatusCacheDAO(contextReference.get().getApplicationContext(), db).updateStatus(BOOKMARK_CACHE, refreshedStatus);
diff --git a/app/src/main/java/app/fedilab/android/client/API.java b/app/src/main/java/app/fedilab/android/client/API.java
index ac023c8ac..af6e8570d 100644
--- a/app/src/main/java/app/fedilab/android/client/API.java
+++ b/app/src/main/java/app/fedilab/android/client/API.java
@@ -749,9 +749,9 @@ public class API {
if (!resobj.isNull("in_reply_to_account_id")) {
status.setIn_reply_to_account_id(resobj.get("in_reply_to_account_id").toString());
}
- if( resobj.has("sensitive")){
+ if (resobj.has("sensitive")) {
status.setSensitive(resobj.getBoolean("sensitive"));
- }else{
+ } else {
status.setSensitive(false);
}
status.setSpoiler_text(resobj.get("spoiler_text").toString());
@@ -853,7 +853,7 @@ public class API {
}
status.setApplication(application);
- status.setAccount(parseAccountResponse(context, resobj.getJSONObject("account")));
+ status.setAccount(parseAccountResponse(context, resobj.getJSONObject("account"), true));
status.setContent(context, resobj.get("content").toString());
if (!resobj.isNull("favourites_count")) {
status.setFavourites_count(resobj.getInt("favourites_count"));
@@ -1236,7 +1236,7 @@ public class API {
} else if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
if (!resobj.isNull("account")) {
- Account account = parseAccountResponse(context, resobj.getJSONObject("account"));
+ Account account = parseAccountResponse(context, resobj.getJSONObject("account"), true);
AccountAdmin accountAdmin = new AccountAdmin();
accountAdmin.setId(account.getId());
accountAdmin.setUsername(account.getAcct());
@@ -1245,7 +1245,7 @@ public class API {
}
if (!resobj.isNull("actor")) {
- Account account = parseAccountResponse(context, resobj.getJSONObject("actor"));
+ Account account = parseAccountResponse(context, resobj.getJSONObject("actor"), true);
AccountAdmin accountAdmin = new AccountAdmin();
accountAdmin.setId(account.getId());
accountAdmin.setUsername(account.getAcct());
@@ -1308,7 +1308,7 @@ public class API {
}
if (!resobj.isNull("account")) {
- accountAdmin.setAccount(parseAccountResponse(context, resobj.getJSONObject("account")));
+ accountAdmin.setAccount(parseAccountResponse(context, resobj.getJSONObject("account"), true));
} else {
Account account = new Account();
account.setId(accountAdmin.getId());
@@ -1359,7 +1359,7 @@ public class API {
* @return Account
*/
@SuppressWarnings("InfiniteRecursion")
- private static Account parseAccountResponse(Context context, JSONObject resobj) {
+ private static Account parseAccountResponse(Context context, JSONObject resobj, boolean fetchEmoji) {
Account account = new Account();
try {
@@ -1399,7 +1399,7 @@ public class API {
account.setBot(false);
}
try {
- account.setMoved_to_account(parseAccountResponse(context, resobj.getJSONObject("moved")));
+ account.setMoved_to_account(parseAccountResponse(context, resobj.getJSONObject("moved"), true));
} catch (Exception ignored) {
account.setMoved_to_account(null);
}
@@ -1420,6 +1420,7 @@ public class API {
}
}
} catch (Exception ignored) {
+ ignored.printStackTrace();
}
try {
@@ -1439,6 +1440,7 @@ public class API {
account.setFields(fieldsMap);
account.setFieldsVerified(fieldsMapVerified);
} catch (Exception ignored) {
+ ignored.printStackTrace();
}
@@ -1478,7 +1480,9 @@ public class API {
} catch (JSONException | ParseException e) {
e.printStackTrace();
}
- Account.makeAccountNameEmoji(context, account);
+ if (fetchEmoji) {
+ Account.makeAccountNameEmoji(context, account);
+ }
return account;
}
@@ -1606,10 +1610,12 @@ public class API {
notification.setId(resobj.get("id").toString());
notification.setType(resobj.get("type").toString());
notification.setCreated_at(Helper.mstStringToDate(resobj.get("created_at").toString()));
- notification.setAccount(parseAccountResponse(context, resobj.getJSONObject("account")));
+ notification.setAccount(parseAccountResponse(context, resobj.getJSONObject("account"), false));
+
try {
notification.setStatus(parseStatuses(context, resobj.getJSONObject("status")));
} catch (Exception ignored) {
+ ignored.printStackTrace();
}
notification.setCreated_at(Helper.mstStringToDate(resobj.get("created_at").toString()));
} catch (JSONException ignored) {
@@ -2450,7 +2456,7 @@ public class API {
return null;
}
String response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/accounts/verify_credentials"), 10, null, prefKeyOauthTokenT);
- account = parseAccountResponse(context, new JSONObject(response));
+ account = parseAccountResponse(context, new JSONObject(response), true);
if (social != null) {
account.setSocial(social.toUpperCase());
}
@@ -2482,7 +2488,7 @@ public class API {
String response;
try {
response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/accounts/verify_credentials"), 10, null, targetedAccount.getToken());
- account = parseAccountResponse(context, new JSONObject(response));
+ account = parseAccountResponse(context, new JSONObject(response), true);
if (social != null) {
account.setSocial(social.toUpperCase());
}
@@ -2578,7 +2584,7 @@ public class API {
account = new Account();
try {
String response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl(String.format("/accounts/%s", accountId)), 10, null, prefKeyOauthTokenT);
- account = parseAccountResponse(context, new JSONObject(response));
+ account = parseAccountResponse(context, new JSONObject(response), true);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
@@ -5736,7 +5742,7 @@ public class API {
}
}
if (resobj.has("contact_account")) {
- instance.setContactAccount(parseAccountResponse(context, resobj.getJSONObject("contact_account")));
+ instance.setContactAccount(parseAccountResponse(context, resobj.getJSONObject("contact_account"), true));
}
} catch (JSONException e) {
e.printStackTrace();
@@ -5968,7 +5974,7 @@ public class API {
int i = 0;
while (i < jsonArray.length()) {
JSONObject resobj = jsonArray.getJSONObject(i);
- Account account = parseAccountResponse(context, resobj);
+ Account account = parseAccountResponse(context, resobj, true);
accounts.add(account);
i++;
}
diff --git a/app/src/main/java/app/fedilab/android/client/Entities/Account.java b/app/src/main/java/app/fedilab/android/client/Entities/Account.java
index 537e81476..93c3d3cf5 100644
--- a/app/src/main/java/app/fedilab/android/client/Entities/Account.java
+++ b/app/src/main/java/app/fedilab/android/client/Entities/Account.java
@@ -245,6 +245,7 @@ public class Account implements Parcelable {
});
} catch (Exception ignored) {
+ ignored.printStackTrace();
}
}
diff --git a/app/src/main/java/app/fedilab/android/drawers/NotificationsListAdapter.java b/app/src/main/java/app/fedilab/android/drawers/NotificationsListAdapter.java
index 8aec4ae91..b4f253b16 100644
--- a/app/src/main/java/app/fedilab/android/drawers/NotificationsListAdapter.java
+++ b/app/src/main/java/app/fedilab/android/drawers/NotificationsListAdapter.java
@@ -532,7 +532,7 @@ public class NotificationsListAdapter extends RecyclerView.Adapter implements On
holder.rated.removeAllViews();
List<Integer> ownvotes = poll.getOwn_votes();
int j = 0;
- if ( poll.getOptionsList() != null) {
+ if (poll.getOptionsList() != null) {
for (PollOptions pollOption : poll.getOptionsList()) {
View item = inflater.inflate(R.layout.layout_poll_item, new LinearLayout(context), false);
double value = ((double) (pollOption.getVotes_count() * 100) / (double) poll.getVoters_count());
diff --git a/app/src/main/java/app/fedilab/android/drawers/ReactionAdapter.java b/app/src/main/java/app/fedilab/android/drawers/ReactionAdapter.java
index c42ad2cc9..5aa0e6d2c 100644
--- a/app/src/main/java/app/fedilab/android/drawers/ReactionAdapter.java
+++ b/app/src/main/java/app/fedilab/android/drawers/ReactionAdapter.java
@@ -45,7 +45,7 @@ public class ReactionAdapter extends RecyclerView.Adapter {
ReactionAdapter(List<Reaction> reactions) {
this.reactions = reactions;
- if( reactions == null){
+ if (reactions == null) {
this.reactions = new ArrayList<>();
}
}
@@ -74,13 +74,13 @@ public class ReactionAdapter extends RecyclerView.Adapter {
holder.reaction_emoji.setContentDescription(reaction.getName());
Helper.loadGiF(holder.itemView.getContext(), reaction.getUrl(), holder.reaction_emoji);
- if( !reaction.getUrl().contains("gif")) {
+ if (!reaction.getUrl().contains("gif")) {
Glide.with(holder.itemView.getContext())
.asDrawable()
.load(reaction.getUrl())
.thumbnail(0.1f)
.into(holder.reaction_emoji);
- }else{
+ } else {
Glide.with(holder.itemView.getContext())
.asGif()
.load(reaction.getUrl())
diff --git a/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java b/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java
index cd5d921e1..940633362 100644
--- a/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java
+++ b/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java
@@ -568,7 +568,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
show_account_boosts = sharedpreferences.getBoolean(Helper.SHOW_ACCOUNT_BOOSTS, true);
show_account_replies = sharedpreferences.getBoolean(Helper.SHOW_ACCOUNT_REPLIES, true);
}
- if (type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE && type != RetrieveFeedsAsyncTask.Type.NEWS && type != RetrieveFeedsAsyncTask.Type.ANNOUNCEMENTS && !Helper.filterToots(statuses.get(position), type, context instanceof ShowAccountActivity, show_account_boosts, show_account_replies)) {
+ if (type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE && type != RetrieveFeedsAsyncTask.Type.NEWS && type != RetrieveFeedsAsyncTask.Type.ANNOUNCEMENTS && !Helper.filterToots(statuses.get(position), type, context instanceof ShowAccountActivity, show_account_boosts, show_account_replies)) {
return HIDDEN_STATUS;
}
if (statuses.get(position).isFocused() && type == RetrieveFeedsAsyncTask.Type.CONTEXT && statuses.get(position).getViewType() != CONSOLE_STATUS)
@@ -1270,11 +1270,11 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
TooltipCompat.setTooltipText(holder.custom_feature_cache, context.getString(R.string.refresh_cache));
holder.custom_feature_cache.setOnClickListener(view -> {
- if( type != RetrieveFeedsAsyncTask.Type.CACHE_BOOKMARKS) {
+ if (type != RetrieveFeedsAsyncTask.Type.CACHE_BOOKMARKS) {
new ManageCachedStatusAsyncTask(context, status.getId(), StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
status.setCustomFeaturesDisplayed(false);
notifyStatusChanged(status);
- }else{
+ } else {
new SyncBookmarksAsyncTask(context, status.getId(), StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
@@ -2143,7 +2143,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
String url = status.getWebviewURL().replaceAll("&amp;", "&");
try {
holder.status_cardview_webview.loadUrl(url);
- }catch (Exception e){
+ } catch (Exception e) {
e.printStackTrace();
}
holder.status_cardview_webview.setVisibility(View.VISIBLE);
@@ -2159,7 +2159,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
String url = status.getReblog().getWebviewURL().replaceAll("&amp;", "&");
try {
holder.status_cardview_webview.loadUrl(url);
- }catch (Exception e){
+ } catch (Exception e) {
e.printStackTrace();
}
holder.status_cardview_webview.setVisibility(View.VISIBLE);
@@ -3999,7 +3999,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
@Override
public void onRetrieveBookmarks(List<Status> statuses) {
- if( statuses != null && statuses.size() > 0 ) {
+ if (statuses != null && statuses.size() > 0) {
notifyStatusChanged(statuses.get(0));
}
}
diff --git a/app/src/main/java/app/fedilab/android/fragments/DisplayFiltersFragment.java b/app/src/main/java/app/fedilab/android/fragments/DisplayFiltersFragment.java
index d67bc6b7a..ea0039c0f 100644
--- a/app/src/main/java/app/fedilab/android/fragments/DisplayFiltersFragment.java
+++ b/app/src/main/java/app/fedilab/android/fragments/DisplayFiltersFragment.java
@@ -15,7 +15,6 @@ package app.fedilab.android.fragments;
* see <http://www.gnu.org/licenses>. */
import android.content.Context;
-import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
@@ -46,6 +45,7 @@ import java.util.List;
import java.util.Objects;
import app.fedilab.android.R;
+import app.fedilab.android.activities.BaseMainActivity;
import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.asynctasks.ManageFiltersAsyncTask;
import app.fedilab.android.client.APIResponse;
@@ -70,7 +70,7 @@ public class DisplayFiltersFragment extends Fragment implements OnFilterActionIn
private Context context;
private AsyncTask<Void, Void, Void> asyncTask;
- private List<Filters> filters;
+
private RelativeLayout mainLoader;
private FloatingActionButton add_new;
private FilterAdapter filterAdapter;
@@ -84,7 +84,6 @@ public class DisplayFiltersFragment extends Fragment implements OnFilterActionIn
View rootView = inflater.inflate(R.layout.fragment_filters, container, false);
context = getContext();
- filters = new ArrayList<>();
lv_filters = rootView.findViewById(R.id.lv_filters);
@@ -93,7 +92,7 @@ public class DisplayFiltersFragment extends Fragment implements OnFilterActionIn
RelativeLayout nextElementLoader = rootView.findViewById(R.id.loading_next_items);
mainLoader.setVisibility(View.VISIBLE);
nextElementLoader.setVisibility(View.GONE);
- filterAdapter = new FilterAdapter(filters, textviewNoAction);
+ filterAdapter = new FilterAdapter(BaseMainActivity.filters, textviewNoAction);
lv_filters.setAdapter(filterAdapter);
asyncTask = new ManageFiltersAsyncTask(context, ManageFiltersAsyncTask.action.GET_ALL_FILTER, null, DisplayFiltersFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
try {
@@ -101,114 +100,100 @@ public class DisplayFiltersFragment extends Fragment implements OnFilterActionIn
} catch (Exception ignored) {
}
if (add_new != null)
- add_new.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
- int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
- int style;
- if (theme == Helper.THEME_DARK) {
- style = R.style.DialogDark;
- } else if (theme == Helper.THEME_BLACK) {
- style = R.style.DialogBlack;
- } else {
- style = R.style.Dialog;
- }
- AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context, style);
- LayoutInflater inflater = getLayoutInflater();
- View dialogView = inflater.inflate(R.layout.add_filter, new LinearLayout(context), false);
- dialogBuilder.setView(dialogView);
+ add_new.setOnClickListener(view -> {
+ final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
+ int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
+ int style;
+ if (theme == Helper.THEME_DARK) {
+ style = R.style.DialogDark;
+ } else if (theme == Helper.THEME_BLACK) {
+ style = R.style.DialogBlack;
+ } else {
+ style = R.style.Dialog;
+ }
+ AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context, style);
+ LayoutInflater inflater1 = getLayoutInflater();
+ View dialogView = inflater1.inflate(R.layout.add_filter, new LinearLayout(context), false);
+ dialogBuilder.setView(dialogView);
- EditText add_phrase = dialogView.findViewById(R.id.add_phrase);
- CheckBox context_home = dialogView.findViewById(R.id.context_home);
- CheckBox context_public = dialogView.findViewById(R.id.context_public);
- CheckBox context_notification = dialogView.findViewById(R.id.context_notification);
- CheckBox context_conversation = dialogView.findViewById(R.id.context_conversation);
- CheckBox context_whole_word = dialogView.findViewById(R.id.context_whole_word);
- CheckBox context_drop = dialogView.findViewById(R.id.context_drop);
- Spinner filter_expire = dialogView.findViewById(R.id.filter_expire);
- ArrayAdapter<CharSequence> adapterResize = ArrayAdapter.createFromResource(Objects.requireNonNull(getActivity()),
- R.array.filter_expire, android.R.layout.simple_spinner_dropdown_item);
- filter_expire.setAdapter(adapterResize);
- final int[] expire = {-1};
- filter_expire.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
- @Override
- public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
- switch (position) {
- case 0:
- expire[0] = -1;
- break;
- case 1:
- expire[0] = 3600;
- break;
- case 2:
- expire[0] = 21600;
- break;
- case 3:
- expire[0] = 43200;
- break;
- case 4:
- expire[0] = 86400;
- break;
- case 5:
- expire[0] = 604800;
- break;
- }
+ EditText add_phrase = dialogView.findViewById(R.id.add_phrase);
+ CheckBox context_home = dialogView.findViewById(R.id.context_home);
+ CheckBox context_public = dialogView.findViewById(R.id.context_public);
+ CheckBox context_notification = dialogView.findViewById(R.id.context_notification);
+ CheckBox context_conversation = dialogView.findViewById(R.id.context_conversation);
+ CheckBox context_whole_word = dialogView.findViewById(R.id.context_whole_word);
+ CheckBox context_drop = dialogView.findViewById(R.id.context_drop);
+ Spinner filter_expire = dialogView.findViewById(R.id.filter_expire);
+ ArrayAdapter<CharSequence> adapterResize = ArrayAdapter.createFromResource(Objects.requireNonNull(getActivity()),
+ R.array.filter_expire, android.R.layout.simple_spinner_dropdown_item);
+ filter_expire.setAdapter(adapterResize);
+ final int[] expire = {-1};
+ filter_expire.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+ switch (position) {
+ case 0:
+ expire[0] = -1;
+ break;
+ case 1:
+ expire[0] = 3600;
+ break;
+ case 2:
+ expire[0] = 21600;
+ break;
+ case 3:
+ expire[0] = 43200;
+ break;
+ case 4:
+ expire[0] = 86400;
+ break;
+ case 5:
+ expire[0] = 604800;
+ break;
}
+ }
- @Override
- public void onNothingSelected(AdapterView<?> parent) {
- }
- });
- dialogBuilder.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int id) {
+ @Override
+ public void onNothingSelected(AdapterView<?> parent) {
+ }
+ });
+ dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> {
- if (add_phrase.getText() != null && add_phrase.getText().toString().trim().length() > 0) {
- Filters filter = new Filters();
- ArrayList<String> contextFilter = new ArrayList<>();
- if (context_home.isChecked())
- contextFilter.add("home");
- if (context_public.isChecked())
- contextFilter.add("public");
- if (context_notification.isChecked())
- contextFilter.add("notifications");
- if (context_conversation.isChecked())
- contextFilter.add("thread");
- filter.setContext(contextFilter);
- filter.setPhrase(add_phrase.getText().toString());
- filter.setExpires_in(expire[0]);
- filter.setWhole_word(context_whole_word.isChecked());
- filter.setIrreversible(context_drop.isChecked());
- new ManageFiltersAsyncTask(context, ManageFiltersAsyncTask.action.CREATE_FILTER, filter, DisplayFiltersFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
- }
- dialog.dismiss();
- add_new.setEnabled(false);
- }
- });
- dialogBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int id) {
- dialog.dismiss();
- }
- });
+ if (add_phrase.getText() != null && add_phrase.getText().toString().trim().length() > 0) {
+ Filters filter = new Filters();
+ ArrayList<String> contextFilter = new ArrayList<>();
+ if (context_home.isChecked())
+ contextFilter.add("home");
+ if (context_public.isChecked())
+ contextFilter.add("public");
+ if (context_notification.isChecked())
+ contextFilter.add("notifications");
+ if (context_conversation.isChecked())
+ contextFilter.add("thread");
+ filter.setContext(contextFilter);
+ filter.setPhrase(add_phrase.getText().toString());
+ filter.setExpires_in(expire[0]);
+ filter.setWhole_word(context_whole_word.isChecked());
+ filter.setIrreversible(context_drop.isChecked());
+ new ManageFiltersAsyncTask(context, ManageFiltersAsyncTask.action.CREATE_FILTER, filter, DisplayFiltersFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
+ }
+ dialog.dismiss();
+ add_new.setEnabled(false);
+ });
+ dialogBuilder.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
- AlertDialog alertDialog = dialogBuilder.create();
- alertDialog.setTitle(getString(R.string.action_filter_create));
- alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
- @Override
- public void onDismiss(DialogInterface dialogInterface) {
- //Hide keyboard
- InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
- assert imm != null;
- imm.hideSoftInputFromWindow(add_phrase.getWindowToken(), 0);
- }
- });
- if (alertDialog.getWindow() != null)
- alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
- alertDialog.show();
- }
+ AlertDialog alertDialog = dialogBuilder.create();
+ alertDialog.setTitle(getString(R.string.action_filter_create));
+ alertDialog.setOnDismissListener(dialogInterface -> {
+ //Hide keyboard
+ InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
+ assert imm != null;
+ imm.hideSoftInputFromWindow(add_phrase.getWindowToken(), 0);
+ });
+ if (alertDialog.getWindow() != null)
+ alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
+ alertDialog.show();
});
return rootView;
}
@