mirror of
https://github.com/nuclearfog/Shitter.git
synced 2025-01-01 04:17:21 +01:00
added refresh icon to exclude list, added toast messages, removed automatic exclude list refreshing
Signed-off-by: nuclearfog <hatespirit666@gmail.com>
This commit is contained in:
parent
bfc77709fe
commit
958a36e4f1
@ -1,16 +1,17 @@
|
||||
package org.nuclearfog.twidda.activity;
|
||||
|
||||
import static android.os.AsyncTask.Status.RUNNING;
|
||||
import static org.nuclearfog.twidda.backend.UserExcludeLoader.Mode.BLOCK_USER;
|
||||
import static org.nuclearfog.twidda.backend.UserExcludeLoader.Mode.MUTE_USER;
|
||||
import static org.nuclearfog.twidda.backend.UserExcludeLoader.Mode.REFRESH;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.SearchView;
|
||||
import androidx.appcompat.widget.SearchView.OnQueryTextListener;
|
||||
@ -79,6 +80,19 @@ public class UserExclude extends AppCompatActivity implements OnTabSelectedListe
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
if (item.getItemId() == R.id.menu_exclude_refresh) {
|
||||
if (userExclTask == null || userExclTask.getStatus() != RUNNING) {
|
||||
Toast.makeText(this, R.string.info_refreshing_exclude_list, Toast.LENGTH_SHORT).show();
|
||||
userExclTask = new UserExcludeLoader(this, REFRESH);
|
||||
userExclTask.execute();
|
||||
}
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu m) {
|
||||
SearchView searchView = (SearchView) m.findItem(R.id.menu_exclude_user).getActionView();
|
||||
@ -93,16 +107,6 @@ public class UserExclude extends AppCompatActivity implements OnTabSelectedListe
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
if (userExclTask == null) {
|
||||
userExclTask = new UserExcludeLoader(this, "");
|
||||
userExclTask.execute(REFRESH);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
@ -127,14 +131,15 @@ public class UserExclude extends AppCompatActivity implements OnTabSelectedListe
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
if (userExclTask == null || userExclTask.getStatus() != AsyncTask.Status.RUNNING) {
|
||||
userExclTask = new UserExcludeLoader(this, query);
|
||||
if (userExclTask == null || userExclTask.getStatus() != RUNNING) {
|
||||
if (tablayout.getSelectedTabPosition() == 0) {
|
||||
userExclTask.execute(MUTE_USER);
|
||||
userExclTask = new UserExcludeLoader(this, MUTE_USER);
|
||||
userExclTask.execute(query);
|
||||
return true;
|
||||
}
|
||||
if (tablayout.getSelectedTabPosition() == 1) {
|
||||
userExclTask.execute(BLOCK_USER);
|
||||
userExclTask = new UserExcludeLoader(this, BLOCK_USER);
|
||||
userExclTask.execute(query);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -161,6 +166,10 @@ public class UserExclude extends AppCompatActivity implements OnTabSelectedListe
|
||||
Toast.makeText(this, R.string.info_user_blocked, Toast.LENGTH_SHORT).show();
|
||||
invalidateOptionsMenu();
|
||||
break;
|
||||
|
||||
case REFRESH:
|
||||
Toast.makeText(this, R.string.info_exclude_list_updated, Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ import java.util.List;
|
||||
*
|
||||
* @author nuclearfog
|
||||
*/
|
||||
public class UserExcludeLoader extends AsyncTask<UserExcludeLoader.Mode, Void, UserExcludeLoader.Mode> {
|
||||
public class UserExcludeLoader extends AsyncTask<String, Void, Void> {
|
||||
|
||||
public enum Mode {
|
||||
REFRESH,
|
||||
@ -31,44 +31,38 @@ public class UserExcludeLoader extends AsyncTask<UserExcludeLoader.Mode, Void, U
|
||||
private WeakReference<UserExclude> callback;
|
||||
private ExcludeDatabase excludeDatabase;
|
||||
private TwitterEngine mTwitter;
|
||||
private String name;
|
||||
private Mode mode;
|
||||
|
||||
|
||||
public UserExcludeLoader(UserExclude callback, String name) {
|
||||
public UserExcludeLoader(UserExclude callback, Mode mode) {
|
||||
super();
|
||||
mTwitter = TwitterEngine.getInstance(callback);
|
||||
excludeDatabase = ExcludeDatabase.getInstance(callback);
|
||||
this.callback = new WeakReference<>(callback);
|
||||
this.name = name;
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Mode doInBackground(Mode... mode) {
|
||||
protected Void doInBackground(String[] names) {
|
||||
try {
|
||||
switch (mode[0]) {
|
||||
case REFRESH:
|
||||
List<Long> ids = mTwitter.getExcludedUserIDs();
|
||||
excludeDatabase.setExcludeList(ids);
|
||||
break;
|
||||
|
||||
case MUTE_USER:
|
||||
mTwitter.muteUser(name);
|
||||
break;
|
||||
|
||||
case BLOCK_USER:
|
||||
mTwitter.blockUser(name);
|
||||
break;
|
||||
if (mode == Mode.REFRESH) {
|
||||
List<Long> ids = mTwitter.getExcludedUserIDs();
|
||||
excludeDatabase.setExcludeList(ids);
|
||||
} else if (mode == Mode.MUTE_USER) {
|
||||
mTwitter.muteUser(names[0]);
|
||||
} else if (mode == Mode.BLOCK_USER) {
|
||||
mTwitter.blockUser(names[0]);
|
||||
}
|
||||
} catch (EngineException err) {
|
||||
this.err = err;
|
||||
}
|
||||
return mode[0];
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Mode mode) {
|
||||
protected void onPostExecute(Void v) {
|
||||
UserExclude activity = callback.get();
|
||||
if (activity != null) {
|
||||
if (err == null) {
|
||||
|
9
app/src/main/res/drawable/refresh.xml
Normal file
9
app/src/main/res/drawable/refresh.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:height="20dp"
|
||||
android:width="20dp"
|
||||
android:viewportHeight="512"
|
||||
android:viewportWidth="512">
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:pathData="M411.826,289.391c0,86.061 -69.766,155.826 -155.826,155.826s-155.826,-69.766 -155.826,-155.826S169.939,133.565 256,133.565v66.783l100.174,-100.174L256,0v66.783c-122.943,0 -222.609,99.665 -222.609,222.609S133.057,512 256,512s222.609,-99.665 222.609,-222.609H411.826z" />
|
||||
</vector>
|
@ -9,4 +9,10 @@
|
||||
app:actionViewClass="androidx.appcompat.widget.SearchView"
|
||||
app:showAsAction="ifRoom|collapseActionView" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_exclude_refresh"
|
||||
android:title="@string/menu_refresh_exclude"
|
||||
android:icon="@drawable/refresh"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
</menu>
|
@ -212,4 +212,7 @@
|
||||
<string name="menu_hint_block_user">\@Name blockieren</string>
|
||||
<string name="menu_exclude_user">Nutzer ausschließen</string>
|
||||
<string name="menu_search_filter">Ergebnisse filtern</string>
|
||||
<string name="menu_refresh_exclude">Filterliste aktualisieren</string>
|
||||
<string name="info_refreshing_exclude_list">aktualisiere Filterliste</string>
|
||||
<string name="info_exclude_list_updated">Filterliste aktualisiert!</string>
|
||||
</resources>
|
@ -150,6 +150,8 @@
|
||||
<string name="info_tweet_removed">Tweet removed</string>
|
||||
<string name="info_tweet_sent">Tweet sent</string>
|
||||
<string name="info_location_pending">Location is pending, please wait.</string>
|
||||
<string name="info_refreshing_exclude_list">refreshing exclude list</string>
|
||||
<string name="info_exclude_list_updated">exclude_list_updated!</string>
|
||||
<string name="info_error">Error</string>
|
||||
|
||||
<!-- toast messages for error information -->
|
||||
@ -223,6 +225,7 @@
|
||||
<string name="menu_search_filter">filter results</string>
|
||||
<string name="menu_hint_mute_user">enter @name to mute</string>
|
||||
<string name="menu_hint_block_user">enter @name to block</string>
|
||||
<string name="menu_refresh_exclude">refresh exclude list</string>
|
||||
|
||||
<!--dialog strings-->
|
||||
<string name="dialog_button_yes">Yes</string>
|
||||
|
Loading…
Reference in New Issue
Block a user