Display home muted
This commit is contained in:
parent
93fce1f56e
commit
7a93b22f77
|
@ -127,6 +127,7 @@ import app.fedilab.android.client.entities.api.Status;
|
|||
import app.fedilab.android.client.entities.app.Account;
|
||||
import app.fedilab.android.client.entities.app.BaseAccount;
|
||||
import app.fedilab.android.client.entities.app.BottomMenu;
|
||||
import app.fedilab.android.client.entities.app.MutedAccounts;
|
||||
import app.fedilab.android.client.entities.app.Pinned;
|
||||
import app.fedilab.android.client.entities.app.PinnedTimeline;
|
||||
import app.fedilab.android.client.entities.app.StatusCache;
|
||||
|
@ -164,6 +165,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
|||
public static status networkAvailable = UNKNOWN;
|
||||
public static Instance instanceInfo;
|
||||
public static List<Filter> mainFilters;
|
||||
public static List<app.fedilab.android.client.entities.api.Account> filteredAccounts;
|
||||
public static boolean filterFetched;
|
||||
public static boolean show_boosts, show_replies, show_art_nsfw;
|
||||
public static String regex_home, regex_local, regex_public;
|
||||
|
@ -302,7 +304,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
|||
} else {
|
||||
BaseMainActivity.currentToken = sharedpreferences.getString(Helper.PREF_USER_TOKEN, null);
|
||||
}
|
||||
|
||||
filteredAccounts = new ArrayList<>();
|
||||
mamageNewIntent(getIntent());
|
||||
filterFetched = false;
|
||||
networkStateReceiver = new NetworkStateReceiver();
|
||||
|
@ -565,6 +567,10 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
|||
currentAccount = new Account(BaseMainActivity.this).getConnectedAccount();
|
||||
//Delete cache older than 7 days
|
||||
new StatusCache(BaseMainActivity.this).deleteForAllAccountAfter7Days();
|
||||
MutedAccounts mutedAccounts = new MutedAccounts(BaseMainActivity.this).getMutedAccount(currentAccount);
|
||||
if (mutedAccounts != null && mutedAccounts.accounts != null) {
|
||||
filteredAccounts = mutedAccounts.accounts;
|
||||
}
|
||||
} catch (DBException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -54,11 +54,12 @@ public class ActionActivity extends BaseBarActivity {
|
|||
binding.muted.setOnClickListener(v -> displayTimeline(Timeline.TimeLineEnum.MUTED_TIMELINE));
|
||||
binding.blocked.setOnClickListener(v -> displayTimeline(Timeline.TimeLineEnum.BLOCKED_TIMELINE));
|
||||
binding.domainBlock.setOnClickListener(v -> displayTimeline(Timeline.TimeLineEnum.BLOCKED_DOMAIN_TIMELINE));
|
||||
binding.mutedHome.setOnClickListener(v -> displayTimeline(Timeline.TimeLineEnum.MUTED_TIMELINE_HOME));
|
||||
}
|
||||
|
||||
private void displayTimeline(Timeline.TimeLineEnum type) {
|
||||
canGoBack = true;
|
||||
if (type == Timeline.TimeLineEnum.MUTED_TIMELINE || type == Timeline.TimeLineEnum.BLOCKED_TIMELINE) {
|
||||
if (type == Timeline.TimeLineEnum.MUTED_TIMELINE || type == Timeline.TimeLineEnum.BLOCKED_TIMELINE || type == Timeline.TimeLineEnum.MUTED_TIMELINE_HOME) {
|
||||
|
||||
ThemeHelper.slideViewsToLeft(binding.buttonContainer, binding.fragmentContainer, () -> {
|
||||
fragmentMastodonAccount = new FragmentMastodonAccount();
|
||||
|
@ -114,6 +115,9 @@ public class ActionActivity extends BaseBarActivity {
|
|||
case BLOCKED_DOMAIN_TIMELINE:
|
||||
setTitle(R.string.blocked_domains);
|
||||
break;
|
||||
case MUTED_TIMELINE_HOME:
|
||||
setTitle(R.string.muted_menu_home);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -388,6 +388,8 @@ public class Timeline {
|
|||
ACCOUNT_TIMELINE("ACCOUNT_TIMELINE"),
|
||||
@SerializedName("MUTED_TIMELINE")
|
||||
MUTED_TIMELINE("MUTED_TIMELINE"),
|
||||
@SerializedName("MUTED_TIMELINE_HOME")
|
||||
MUTED_TIMELINE_HOME("MUTED_TIMELINE_HOME"),
|
||||
@SerializedName("BOOKMARK_TIMELINE")
|
||||
BOOKMARK_TIMELINE("BOOKMARK_TIMELINE"),
|
||||
@SerializedName("BLOCKED_DOMAIN_TIMELINE")
|
||||
|
|
|
@ -14,6 +14,8 @@ package app.fedilab.android.helper;
|
|||
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import static app.fedilab.android.BaseMainActivity.filteredAccounts;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
|
@ -35,6 +37,7 @@ import java.util.regex.Pattern;
|
|||
import app.fedilab.android.BaseMainActivity;
|
||||
import app.fedilab.android.activities.MainActivity;
|
||||
import app.fedilab.android.client.endpoints.MastodonFiltersService;
|
||||
import app.fedilab.android.client.entities.api.Account;
|
||||
import app.fedilab.android.client.entities.api.Filter;
|
||||
import app.fedilab.android.client.entities.api.Notification;
|
||||
import app.fedilab.android.client.entities.api.Status;
|
||||
|
@ -90,6 +93,7 @@ public class TimelineHelper {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
//If there are filters:
|
||||
if (BaseMainActivity.mainFilters != null && BaseMainActivity.mainFilters.size() > 0 && statuses != null && statuses.size() > 0) {
|
||||
|
||||
|
@ -143,6 +147,23 @@ public class TimelineHelper {
|
|||
Matcher ms = p.matcher(spoilerText);
|
||||
if (ms.find()) {
|
||||
status.filteredByApp = filter;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (filterTimeLineType == Timeline.TimeLineEnum.HOME) {
|
||||
if (filteredAccounts != null && filteredAccounts.size() > 0) {
|
||||
for (Account account : filteredAccounts) {
|
||||
if (account.acct.equals(status.account.acct)) {
|
||||
Filter filterCustom = new Filter();
|
||||
filterCustom.filter_action = "hide";
|
||||
ArrayList<String> contextCustom = new ArrayList<>();
|
||||
contextCustom.add("home");
|
||||
filterCustom.title = "Fedilab";
|
||||
filterCustom.context = contextCustom;
|
||||
status.filteredByApp = filterCustom;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import java.util.List;
|
|||
|
||||
import app.fedilab.android.BaseMainActivity;
|
||||
import app.fedilab.android.R;
|
||||
import app.fedilab.android.activities.MainActivity;
|
||||
import app.fedilab.android.client.entities.api.Account;
|
||||
import app.fedilab.android.client.entities.api.Accounts;
|
||||
import app.fedilab.android.client.entities.api.Pagination;
|
||||
|
@ -128,6 +129,11 @@ public class FragmentMastodonAccount extends Fragment {
|
|||
accountsVM.getMutes(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, String.valueOf(MastodonHelper.accountsPerCall(requireActivity())), max_id, null)
|
||||
.observe(getViewLifecycleOwner(), this::dealWithPagination);
|
||||
}
|
||||
} else if (timelineType == Timeline.TimeLineEnum.MUTED_TIMELINE_HOME) {
|
||||
if (firstLoad) {
|
||||
accountsVM.getMutedHome(MainActivity.currentAccount)
|
||||
.observe(getViewLifecycleOwner(), this::initializeAccountCommonView);
|
||||
}
|
||||
} else if (timelineType == Timeline.TimeLineEnum.BLOCKED_TIMELINE) {
|
||||
if (firstLoad) {
|
||||
accountsVM.getBlocks(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, String.valueOf(MastodonHelper.accountsPerCall(requireActivity())), null, null)
|
||||
|
|
|
@ -752,6 +752,33 @@ public class AccountsVM extends AndroidViewModel {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Mute the given account in db
|
||||
*
|
||||
* @return {@link LiveData} containing the {@link Account} to the given account
|
||||
*/
|
||||
public LiveData<Accounts> getMutedHome(@NonNull BaseAccount forAccount) {
|
||||
accountsMutableLiveData = new MutableLiveData<>();
|
||||
new Thread(() -> {
|
||||
Accounts accounts = new Accounts();
|
||||
MutedAccounts mutedAccount;
|
||||
try {
|
||||
mutedAccount = new MutedAccounts(getApplication().getApplicationContext()).getMutedAccount(forAccount);
|
||||
if (mutedAccount != null) {
|
||||
accounts.accounts = mutedAccount.accounts;
|
||||
}
|
||||
accounts.pagination = new Pagination();
|
||||
} catch (DBException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> accountsMutableLiveData.setValue(accounts);
|
||||
mainHandler.post(myRunnable);
|
||||
}).start();
|
||||
return accountsMutableLiveData;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Mute the given account in db
|
||||
*
|
||||
|
|
|
@ -12,12 +12,27 @@
|
|||
android:orientation="vertical"
|
||||
android:padding="24dp">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/bookmarks"
|
||||
style="@style/Widget.Material3.Button.OutlinedButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingVertical="12dp"
|
||||
android:text="@string/bookmarks"
|
||||
android:textAlignment="textStart"
|
||||
android:textColor="?attr/colorAccent"
|
||||
app:icon="@drawable/ic_baseline_navigate_next_24"
|
||||
app:iconGravity="end"
|
||||
app:iconTint="?attr/colorAccent"
|
||||
app:strokeColor="?attr/colorAccent" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/muted"
|
||||
style="@style/Widget.Material3.Button.OutlinedButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingVertical="12dp"
|
||||
android:layout_marginTop="24dp"
|
||||
android:text="@string/muted_menu"
|
||||
android:textAlignment="textStart"
|
||||
android:textColor="?attr/colorAccent"
|
||||
|
@ -26,6 +41,21 @@
|
|||
app:iconTint="?attr/colorAccent"
|
||||
app:strokeColor="?attr/colorAccent" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/muted_home"
|
||||
style="@style/Widget.Material3.Button.OutlinedButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:paddingVertical="12dp"
|
||||
android:text="@string/muted_menu_home"
|
||||
android:textAlignment="textStart"
|
||||
android:textColor="?attr/colorAccent"
|
||||
app:icon="@drawable/ic_baseline_navigate_next_24"
|
||||
app:iconGravity="end"
|
||||
app:iconTint="?attr/colorAccent"
|
||||
app:strokeColor="?attr/colorAccent" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/blocked"
|
||||
style="@style/Widget.Material3.Button.OutlinedButton"
|
||||
|
@ -41,20 +71,6 @@
|
|||
app:iconTint="?attr/colorAccent"
|
||||
app:strokeColor="?attr/colorAccent" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/bookmarks"
|
||||
style="@style/Widget.Material3.Button.OutlinedButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:paddingVertical="12dp"
|
||||
android:text="@string/bookmarks"
|
||||
android:textAlignment="textStart"
|
||||
android:textColor="?attr/colorAccent"
|
||||
app:icon="@drawable/ic_baseline_navigate_next_24"
|
||||
app:iconGravity="end"
|
||||
app:iconTint="?attr/colorAccent"
|
||||
app:strokeColor="?attr/colorAccent" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/favourites"
|
||||
|
|
|
@ -54,6 +54,7 @@
|
|||
<string name="home_menu">Home</string>
|
||||
<string name="local_menu">Local timeline</string>
|
||||
<string name="muted_menu">Muted users</string>
|
||||
<string name="muted_menu_home">Home muted users</string>
|
||||
<string name="blocked_menu">Blocked users</string>
|
||||
<string name="notifications">Notifications</string>
|
||||
<string name="follow_request">Follow requests</string>
|
||||
|
|
Loading…
Reference in New Issue