mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2024-12-23 09:10:04 +02:00
some changes
This commit is contained in:
parent
e55c154139
commit
eca5cecd93
6 changed files with 77 additions and 10 deletions
|
@ -37,6 +37,7 @@ import android.os.Looper;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
|
import android.util.Log;
|
||||||
import android.util.Patterns;
|
import android.util.Patterns;
|
||||||
import android.view.ContextThemeWrapper;
|
import android.view.ContextThemeWrapper;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
|
@ -75,6 +76,7 @@ import com.bumptech.glide.load.resource.gif.GifDrawable;
|
||||||
import com.bumptech.glide.request.target.CustomTarget;
|
import com.bumptech.glide.request.target.CustomTarget;
|
||||||
import com.bumptech.glide.request.transition.Transition;
|
import com.bumptech.glide.request.transition.Transition;
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
|
import com.google.android.material.tabs.TabLayout;
|
||||||
import com.jaredrummler.cyanea.Cyanea;
|
import com.jaredrummler.cyanea.Cyanea;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -1135,7 +1137,28 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
int selectedTab = binding.tabLayout.getSelectedTabPosition();
|
||||||
|
TabLayout.Tab tab = binding.tabLayout.getTabAt(selectedTab);
|
||||||
|
Log.v(Helper.TAG, "selectedTab: " + selectedTab);
|
||||||
|
Log.v(Helper.TAG, "tab: " + tab);
|
||||||
|
View view = null;
|
||||||
|
if (tab != null) {
|
||||||
|
view = tab.getCustomView();
|
||||||
|
}
|
||||||
|
if (view != null) {
|
||||||
|
Log.v(Helper.TAG, "view: " + view);
|
||||||
|
TextView counter = view.findViewById(R.id.tab_counter);
|
||||||
|
Log.v(Helper.TAG, "counter: " + counter);
|
||||||
|
if (counter != null) {
|
||||||
|
if (count > 0) {
|
||||||
|
counter.setVisibility(View.VISIBLE);
|
||||||
|
counter.setText(String.valueOf(count));
|
||||||
|
} else {
|
||||||
|
counter.setVisibility(View.GONE);
|
||||||
|
counter.setText("0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -175,20 +175,21 @@ public class StatusCache {
|
||||||
* Insert or update a status
|
* Insert or update a status
|
||||||
*
|
*
|
||||||
* @param statusCache {@link StatusCache}
|
* @param statusCache {@link StatusCache}
|
||||||
* @return long - db id
|
* @return int - 0 if updated 1 if inserted
|
||||||
* @throws DBException exception with database
|
* @throws DBException exception with database
|
||||||
*/
|
*/
|
||||||
public long insertOrUpdate(StatusCache statusCache, String slug) throws DBException {
|
public int insertOrUpdate(StatusCache statusCache, String slug) throws DBException {
|
||||||
if (db == null) {
|
if (db == null) {
|
||||||
throw new DBException("db is null. Wrong initialization.");
|
throw new DBException("db is null. Wrong initialization.");
|
||||||
}
|
}
|
||||||
statusCache.slug = slug;
|
statusCache.slug = slug;
|
||||||
boolean exists = statusExist(statusCache);
|
boolean exists = statusExist(statusCache);
|
||||||
long idReturned;
|
int idReturned = 0;
|
||||||
if (exists) {
|
if (exists) {
|
||||||
idReturned = updateStatus(statusCache);
|
updateStatus(statusCache);
|
||||||
} else {
|
} else {
|
||||||
idReturned = insertStatus(statusCache, slug);
|
insertStatus(statusCache, slug);
|
||||||
|
idReturned = 1;
|
||||||
}
|
}
|
||||||
return idReturned;
|
return idReturned;
|
||||||
}
|
}
|
||||||
|
|
|
@ -325,7 +325,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
int insertedStatus = updateStatusListWith(fetched_statuses.statuses);
|
int insertedStatus = updateStatusListWith(fetched_statuses.statuses);
|
||||||
|
|
||||||
//For these directions, the app will display counters for new messages
|
//For these directions, the app will display counters for new messages
|
||||||
if (insertedStatus >= 0 && (direction == DIRECTION.FETCH_NEW || direction == DIRECTION.SCROLL_TOP)) {
|
if (insertedStatus >= 0 && update != null && (direction == DIRECTION.FETCH_NEW || direction == DIRECTION.SCROLL_TOP)) {
|
||||||
update.onUpdate(insertedStatus, timelineType, slug);
|
update.onUpdate(insertedStatus, timelineType, slug);
|
||||||
}
|
}
|
||||||
if (direction == DIRECTION.TOP && fetchingMissing) {
|
if (direction == DIRECTION.TOP && fetchingMissing) {
|
||||||
|
@ -424,7 +424,8 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
||||||
binding.recyclerView.setLayoutManager(mLayoutManager);
|
binding.recyclerView.setLayoutManager(mLayoutManager);
|
||||||
binding.recyclerView.setAdapter(statusAdapter);
|
binding.recyclerView.setAdapter(statusAdapter);
|
||||||
|
//Fetching new messages
|
||||||
|
route(DIRECTION.FETCH_NEW, true);
|
||||||
|
|
||||||
if (searchCache == null && timelineType != Timeline.TimeLineEnum.TREND_MESSAGE) {
|
if (searchCache == null && timelineType != Timeline.TimeLineEnum.TREND_MESSAGE) {
|
||||||
binding.recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
binding.recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||||
|
@ -460,6 +461,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -484,8 +486,10 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
if (!timelineStatuses.contains(statusReceived) && !statusReceived.pinned && timelineType != Timeline.TimeLineEnum.ACCOUNT_TIMELINE) {
|
if (!timelineStatuses.contains(statusReceived) && !statusReceived.pinned && timelineType != Timeline.TimeLineEnum.ACCOUNT_TIMELINE) {
|
||||||
timelineStatuses.add(position, statusReceived);
|
timelineStatuses.add(position, statusReceived);
|
||||||
statusAdapter.notifyItemInserted(position);
|
statusAdapter.notifyItemInserted(position);
|
||||||
|
if (!statusReceived.cached) {
|
||||||
insertedStatus++;
|
insertedStatus++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
position++;
|
position++;
|
||||||
|
|
|
@ -428,7 +428,10 @@ public class TimelinesVM extends AndroidViewModel {
|
||||||
statusCache.type = timelineParams.type;
|
statusCache.type = timelineParams.type;
|
||||||
statusCache.status_id = status.id;
|
statusCache.status_id = status.id;
|
||||||
try {
|
try {
|
||||||
statusCacheDAO.insertOrUpdate(statusCache, timelineParams.slug);
|
int inserted = statusCacheDAO.insertOrUpdate(statusCache, timelineParams.slug);
|
||||||
|
if (inserted == 0) {
|
||||||
|
status.cached = true;
|
||||||
|
}
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatImageView
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
|
@ -8,4 +9,21 @@
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_centerInParent="true" />
|
android:layout_centerInParent="true" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tab_counter"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignTop="@+id/icon"
|
||||||
|
android:layout_alignEnd="@+id/icon"
|
||||||
|
android:layout_alignParentTop="true"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:background="@drawable/shape_counter"
|
||||||
|
android:paddingLeft="2dp"
|
||||||
|
android:paddingRight="2dp"
|
||||||
|
android:textColor="?mTextColor"
|
||||||
|
android:textSize="12sp"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:text="35"
|
||||||
|
tools:visibility="visible" />
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatImageView
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
|
@ -20,4 +21,21 @@
|
||||||
android:maxWidth="150dp"
|
android:maxWidth="150dp"
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:textSize="16sp" />
|
android:textSize="16sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tab_counter"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignTop="@+id/icon"
|
||||||
|
android:layout_alignEnd="@+id/icon"
|
||||||
|
android:layout_alignParentTop="true"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:background="@drawable/shape_counter"
|
||||||
|
android:paddingLeft="2dp"
|
||||||
|
android:paddingRight="2dp"
|
||||||
|
android:textColor="?mTextColor"
|
||||||
|
android:textSize="12sp"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:text="35"
|
||||||
|
tools:visibility="visible" />
|
||||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||||
|
|
Loading…
Reference in a new issue