Some layout improvements

This commit is contained in:
Thomas 2022-05-12 15:12:18 +02:00
parent ed3d978b03
commit 724b43ca4d
21 changed files with 194 additions and 131 deletions

View File

@ -153,6 +153,7 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.github.amoskorir:avatarimagegenerator:1.5.0'
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.1.0'
implementation 'com.github.GrenderG:Toasty:1.5.2'
implementation 'com.google.android.exoplayer:exoplayer:2.12.2'

View File

@ -94,12 +94,11 @@ public class AccountActivity extends BaseActivity {
setTitle(String.format("@%s", account.getUsername()));
Helper.loadGiF(AccountActivity.this, account.getAvatar().getPath(), binding.profilePicture);
Helper.loadAvatar(AccountActivity.this, account, binding.profilePicture);
binding.username.setText(String.format("@%s", account.getUsername()));
binding.displayname.setText(account.getDisplayName());
binding.instance.setText(account.getHost());
binding.editProfile.setOnClickListener(v -> startActivity(new Intent(AccountActivity.this, MyAccountActivity.class)));
binding.logoutButton.setOnClickListener(v -> {
AlertDialog.Builder dialogBuilderLogoutAccount = new AlertDialog.Builder(AccountActivity.this);
@ -216,7 +215,6 @@ public class AccountActivity extends BaseActivity {
} else {
binding.accountTabLayout.setVisibility(View.GONE);
binding.accountViewpager.setVisibility(View.GONE);
binding.editProfile.setVisibility(View.GONE);
binding.remoteAccount.setVisibility(View.VISIBLE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)

View File

@ -111,31 +111,23 @@ public class MainActivity extends BaseMainActivity {
String type = null;
if (itemId == R.id.navigation_discover) {
setTitleCustom(R.string.title_discover);
binding.viewpager.setCurrentItem(0);
binding.viewpager.setCurrentItem(3);
type = HelperAcadInstance.DISCOVER;
} else if (itemId == R.id.navigation_subscription) {
binding.viewpager.setCurrentItem(1);
binding.viewpager.setCurrentItem(4);
setTitleCustom(R.string.subscriptions);
type = HelperAcadInstance.SUBSCRIPTIONS;
} else if (itemId == R.id.navigation_trending) {
setTitleCustom(R.string.title_trending);
if (Helper.isLoggedIn(MainActivity.this)) {
binding.viewpager.setCurrentItem(2);
} else {
binding.viewpager.setCurrentItem(1);
}
type = HelperAcadInstance.TRENDING;
} else if (itemId == R.id.navigation_most_liked) {
setTitleCustom(R.string.title_most_liked);
binding.viewpager.setCurrentItem(2);
type = HelperAcadInstance.MOSTLIKED;
type = HelperAcadInstance.TRENDING;
} else if (itemId == R.id.navigation_recently_added) {
setTitleCustom(R.string.title_recently_added);
binding.viewpager.setCurrentItem(3);
binding.viewpager.setCurrentItem(1);
type = HelperAcadInstance.RECENTLY_ADDED;
} else if (itemId == R.id.navigation_local) {
setTitleCustom(R.string.title_local);
binding.viewpager.setCurrentItem(4);
binding.viewpager.setCurrentItem(0);
type = HelperAcadInstance.LOCAL;
}
if (type != null) {
@ -281,7 +273,11 @@ public class MainActivity extends BaseMainActivity {
invalidateOptionsMenu();
}).start();
}
binding.viewpager.setOffscreenPageLimit(5);
if (Helper.isLoggedIn(MainActivity.this)) {
binding.viewpager.setOffscreenPageLimit(5);
}else {
binding.viewpager.setOffscreenPageLimit(4);
}
Matomo.sendEvent(MainActivity.this, "UTILISATEUR", "DEMARRAGE", HelperInstance.getLiveInstance(MainActivity.this), Helper.isLoggedIn(MainActivity.this) ? 1 : 0);
@ -555,7 +551,7 @@ public class MainActivity extends BaseMainActivity {
playslistItem.setVisible(!BuildConfig.full_instances);
historyItem.setVisible(false);
settingsItem.setVisible(true);
mostLikedItem.setVisible(false);
mostLikedItem.setVisible(true);
incognitoItem.setVisible(false);
}
break;
@ -790,28 +786,26 @@ public class MainActivity extends BaseMainActivity {
if (Helper.isLoggedIn(MainActivity.this)) {
switch (position) {
case 0:
return overviewFragment;
return locaFragment;
case 1:
return subscriptionFragment;
return recentFragment;
case 2:
return trendingFragment;
case 3:
return recentFragment;
return overviewFragment;
case 4:
return locaFragment;
return subscriptionFragment;
}
} else {
switch (position) {
case 0:
return overviewFragment;
case 1:
return trendingFragment;
case 2:
return mostLikedFragment;
case 3:
return recentFragment;
case 4:
return locaFragment;
case 1:
return recentFragment;
case 2:
return trendingFragment;
case 3:
return overviewFragment;
}
}
return overviewFragment;
@ -819,7 +813,11 @@ public class MainActivity extends BaseMainActivity {
@Override
public int getCount() {
return 5;
if (Helper.isLoggedIn(MainActivity.this)) {
return 5;
}else {
return 4;
}
}
}
}

View File

@ -99,8 +99,7 @@ public class MyAccountActivity extends BaseActivity {
initializeValues(notificationSettings.getNewCommentOnMyVideo(), binding.notifNewCommentApp, binding.notifNewCommentMail);
initializeValues(notificationSettings.getNewVideoFromSubscription(), binding.notifNewVideoApp, binding.notifNewVideoMail);
Helper.loadGiF(MyAccountActivity.this, MainActivity.userMe.getAccount().getAvatar() != null ? MainActivity.userMe.getAccount().getAvatar().getPath() : null, binding.profilePicture);
Helper.loadAvatar(MyAccountActivity.this, MainActivity.userMe.getAccount(), binding.profilePicture);
String[] refresh_array = getResources().getStringArray(R.array.refresh_time);
ArrayAdapter<String> refreshArray = new ArrayAdapter<>(MyAccountActivity.this,
android.R.layout.simple_spinner_dropdown_item, refresh_array);

View File

@ -23,6 +23,7 @@ import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.REPO
import static app.fedilab.fedilabtube.helper.Helper.canMakeAction;
import static app.fedilab.fedilabtube.helper.Helper.getAttColor;
import static app.fedilab.fedilabtube.helper.Helper.isLoggedIn;
import static app.fedilab.fedilabtube.helper.Helper.loadAvatar;
import static app.fedilab.fedilabtube.helper.Helper.loadGiF;
import static app.fedilab.fedilabtube.helper.Helper.peertubeInformation;
@ -307,7 +308,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
if (Helper.canMakeAction(PeertubeActivity.this) && !sepiaSearch) {
Account account = new AccountDAO(PeertubeActivity.this, db).getAccountByToken(token);
Helper.loadGiF(PeertubeActivity.this, account.getAvatar() != null ? account.getAvatar().getPath() : null, binding.myPp);
Helper.loadAvatar(PeertubeActivity.this, account, binding.myPp);
}
isRemote = false;
TorrentOptions torrentOptions = new TorrentOptions.Builder()
@ -1059,13 +1060,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
binding.peertubeDislikeCount.setText(Helper.withSuffix(peertube.getDislikes()));
binding.peertubeLikeCount.setText(Helper.withSuffix(peertube.getLikes()));
binding.peertubeViewCount.setText(Helper.withSuffix(peertube.getViews()));
String ppChannelURL;
if (sepiaSearch) {
ppChannelURL = peertube.getChannel().getAvatar() != null ? "https://" + peertubeInstance + peertube.getChannel().getAvatar().getPath() : null;
} else {
ppChannelURL = peertube.getChannel().getAvatar() != null ? peertube.getChannel().getAvatar().getPath() : null;
}
loadGiF(PeertubeActivity.this, ppChannelURL, binding.ppChannel);
loadAvatar(PeertubeActivity.this, peertube.getChannel(), binding.ppChannel);
binding.ppChannel.setOnClickListener(v -> {
Intent intent = new Intent(PeertubeActivity.this, ShowChannelActivity.class);
Bundle b = new Bundle();
@ -2004,7 +1999,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
if (comment != null) {
binding.replyContent.setVisibility(View.VISIBLE);
Account account = comment.getAccount();
Helper.loadGiF(PeertubeActivity.this, account.getAvatar() != null ? account.getAvatar().getPath() : null, binding.commentAccountProfile);
Helper.loadAvatar(PeertubeActivity.this, account, binding.commentAccountProfile);
binding.commentAccountDisplayname.setText(account.getDisplayName());
binding.commentAccountUsername.setText(account.getAcct());
Spanned commentSpan;

View File

@ -221,7 +221,7 @@ public class ShowAccountActivity extends BaseActivity {
account_dn.setText(account.getDisplayName());
manageNotes(account);
Helper.loadGiF(ShowAccountActivity.this, account.getAvatar() != null ? account.getAvatar().getPath() : null, account_pp);
Helper.loadAvatar(ShowAccountActivity.this, account, account_pp);
}
@Override

View File

@ -323,7 +323,7 @@ public class ShowChannelActivity extends BaseActivity {
manageNotes(channel);
Helper.loadGiF(ShowChannelActivity.this, sepiaSearch ? peertubeInstance : null, channel.getAvatar() != null ? channel.getAvatar().getPath() : null, account_pp);
Helper.loadAvatar(ShowChannelActivity.this, channel, account_pp);
//Follow button
String target = channel.getAcct();

View File

@ -62,8 +62,7 @@ public class AccountsHorizontalListAdapter extends RecyclerView.Adapter<Recycler
holder.binding.accountDn.setText(channel.getName().replace("@", ""));
//Profile picture
Helper.loadGiF(context, channel.getAvatar() != null ? channel.getAvatar().getPath() : null, holder.binding.accountPp, 270);
Helper.loadAvatar(context, channel, holder.binding.accountPp);
if (channel.isSelected()) {
holder.binding.mainContainer.setBackgroundColor(ColorUtils.setAlphaComponent(ContextCompat.getColor(context, Helper.getColorAccent()), 50));
} else {

View File

@ -86,7 +86,7 @@ public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
account.setDescription("");
}
//Profile picture
Helper.loadGiF(context, account.getAvatar() != null ? account.getAvatar().getPath() : null, holder.account_pp);
Helper.loadAvatar(context, account, holder.account_pp);
//Follow button
if (type == RetrofitPeertubeAPI.DataType.MUTED) {
holder.account_action.show();

View File

@ -74,7 +74,7 @@ public class ChannelListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
}
//Profile picture
Helper.loadGiF(context, channel.getAvatar() != null ? channel.getAvatar().getPath() : null, holder.account_pp);
Helper.loadAvatar(context, channel, holder.account_pp);
if (!isMyChannel(channel)) {
holder.more_actions.setVisibility(View.GONE);

View File

@ -275,18 +275,7 @@ public class CommentListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
holder.binding.commentDate.setText(Helper.dateDiff(context, comment.getCreatedAt()));
String avatarUrl;
if (instance != null) {
if (comment.getAccount().getAvatar() != null && comment.getAccount().getAvatar().getPath().startsWith("http")) {
avatarUrl = comment.getAccount().getAvatar().getPath();
} else {
avatarUrl = comment.getAccount().getAvatar() != null ? "https://" + instance + comment.getAccount().getAvatar().getPath() : null;
}
} else {
avatarUrl = comment.getAccount().getAvatar() != null ? comment.getAccount().getAvatar().getPath() : null;
}
Helper.loadGiF(context, avatarUrl, holder.binding.commentAccountProfile);
Helper.loadAvatar(context, comment.getAccount(), holder.binding.commentAccountProfile);
holder.binding.commentAccountProfile.setOnClickListener(v -> {
Bundle b = new Bundle();
Intent intent = new Intent(context, ShowAccountActivity.class);

View File

@ -79,12 +79,7 @@ public class OwnAccountsAdapter extends ArrayAdapter<Account> {
holder.account_un.setText(String.format("@%s", account.getAcct()));
//Profile picture
if (account.getAvatar() != null && account.getAvatar().getPath().startsWith("http")) {
Helper.loadGiF(holder.account_pp.getContext(), account.getAvatar().getPath(), holder.account_pp);
} else {
Helper.loadGiF(holder.account_pp.getContext(), "https://" + account.getHost() + account.getAvatar().getPath(), holder.account_pp);
}
Helper.loadAvatar(holder.account_pp.getContext(), account, holder.account_pp);
return convertView;
}

View File

@ -144,8 +144,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
holder.binding.peertubeAccountName.setText(video.getChannel().getAcct());
Helper.loadGiF(context, instance, video.getChannel().getAvatar() != null ? video.getChannel().getAvatar().getPath() : null, holder.binding.peertubeProfile);
Helper.loadAvatar(context, video.getChannel(), holder.binding.peertubeProfile);
holder.binding.peertubeTitle.setText(video.getName());
if (video.isLive()) {
holder.binding.peertubeDuration.setText(R.string.live);

View File

@ -104,8 +104,7 @@ public class PeertubeNotificationsListAdapter extends RecyclerView.Adapter<Recyc
accountAction.setUsername(actor.getName());
holder.peertube_notif_message.setOnClickListener(v -> markAsRead(notification, position));
} else if (notification.getComment() != null) { //Comment Notification
String profileUrl = notification.getComment().getAccount().getAvatar() != null ? notification.getComment().getAccount().getAvatar().getPath() : null;
Helper.loadGiF(context, profileUrl, holder.peertube_notif_pp);
Helper.loadAvatar(context, notification.getComment().getAccount(), holder.peertube_notif_pp);
accountAction = notification.getComment().getAccount();
String message = context.getString(R.string.peertube_comment_on_video, accountAction.getDisplayName(), accountAction.getUsername());

View File

@ -277,15 +277,7 @@ public class DisplayChannelsFragment extends Fragment implements ChannelListAdap
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
startActivityForResult(intent, PICK_AVATAR);
});
if (position >= 0) {
Helper.loadGiF(context, channels.get(position).getAvatar() != null ? channels.get(position).getAvatar().getPath() : null, bindingDialog.profilePicture);
} else {
Glide.with(context)
.load(R.drawable.missing_peertube)
.thumbnail(0.1f)
.apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(10)))
.into(bindingDialog.profilePicture);
}
Helper.loadAvatar(context, channels.get(position), bindingDialog.profilePicture);
int finalPosition = position;
alertDialog.setOnShowListener(dialogInterface -> {

View File

@ -26,9 +26,11 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
@ -48,6 +50,7 @@ import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import com.avatarfirst.avatargenlib.AvatarGenerator;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
@ -286,6 +289,113 @@ public class Helper {
loadGif(context, null, url, imageView, round, false);
}
public static void loadAvatar(final Context context, Account account, final ImageView imageView) {
String url = null;
if(account.getAvatar() != null) {
url = account.getAvatar().getPath();
}
String instance = account.getHost();
if (url == null || url.trim().toLowerCase().compareTo("null") == 0 || url.endsWith("null")) {
BitmapDrawable avatar = new AvatarGenerator.AvatarBuilder(context)
.setLabel(account.getAcct())
.setAvatarSize(120)
.setTextSize(30)
.toSquare()
.setBackgroundColor(Helper.fetchAccentColor(context))
.build();
Glide.with(imageView.getContext())
.asDrawable()
.load(avatar)
.apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(10)))
.into(imageView);
return;
}
if (url.startsWith("/")) {
url = instance != null ? instance + url : HelperInstance.getLiveInstance(context) + url;
}
if (!url.startsWith("http")) {
url = "https://" + url;
}
try {
RequestBuilder<Drawable> requestBuilder = Glide.with(imageView.getContext())
.load(url)
.thumbnail(0.1f);
requestBuilder.apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(10)))
.into(imageView);
} catch (Exception e) {
try {
BitmapDrawable avatar = new AvatarGenerator.AvatarBuilder(context)
.setLabel(account.getAcct())
.setAvatarSize(120)
.setTextSize(30)
.toSquare()
.setBackgroundColor(fetchAccentColor(context))
.build();
Glide.with(imageView.getContext())
.asDrawable()
.load(avatar)
.apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(10)))
.into(imageView);
} catch (Exception ignored) {
}
}
}
public static void loadAvatar(final Context context, ChannelData.Channel channel, final ImageView imageView) {
String url = null;
if(channel.getAvatar() != null) {
url = channel.getAvatar().getPath();
}
String instance = channel.getHost();
if (url == null || url.trim().toLowerCase().compareTo("null") == 0 || url.endsWith("null")) {
BitmapDrawable avatar = new AvatarGenerator.AvatarBuilder(context)
.setLabel(channel.getAcct())
.setAvatarSize(120)
.setTextSize(30)
.toSquare()
.setBackgroundColor(fetchAccentColor(context))
.build();
Glide.with(imageView.getContext())
.asDrawable()
.load(avatar)
.apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(10)))
.into(imageView);
return;
}
if (url.startsWith("/")) {
url = instance != null ? instance + url : HelperInstance.getLiveInstance(context) + url;
}
if (!url.startsWith("http")) {
url = "https://" + url;
}
try {
RequestBuilder<Drawable> requestBuilder = Glide.with(imageView.getContext())
.load(url)
.thumbnail(0.1f);
requestBuilder.apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(10)))
.into(imageView);
} catch (Exception e) {
try {
BitmapDrawable avatar = new AvatarGenerator.AvatarBuilder(context)
.setLabel(channel.getAcct())
.setAvatarSize(120)
.setTextSize(30)
.toSquare()
.setBackgroundColor(fetchAccentColor(context))
.build();
Glide.with(imageView.getContext())
.asDrawable()
.load(avatar)
.apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(10)))
.into(imageView);
} catch (Exception ignored) {
}
}
}
@SuppressLint("CheckResult")
@SuppressWarnings("SameParameterValue")
private static void loadGif(final Context context, String instance, String url, final ImageView imageView, int round, boolean blur) {
@ -481,6 +591,13 @@ public class Helper {
return ContextCompat.getColor(context, typedValue.resourceId);
}
public static int fetchAccentColor(Context context) {
TypedValue typedValue = new TypedValue();
TypedArray a = context.obtainStyledAttributes(typedValue.data, new int[] { R.attr.colorAccent });
int color = a.getColor(0, 0);
a.recycle();
return color;
}
/**
* Returns boolean depending if the user is authenticated

View File

@ -61,28 +61,13 @@
<ImageView
android:id="@+id/profile_picture"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_width="72dp"
android:layout_height="72dp"
android:contentDescription="@string/profile_picture"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/edit_profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginTop="50dp"
android:contentDescription="@string/edit_profile"
android:scaleType="center"
android:src="@drawable/ic_baseline_edit_24"
android:tint="@color/white"
app:fabSize="mini"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/displayname"
android:layout_width="wrap_content"

View File

@ -2,19 +2,9 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/navigation_discover"
android:icon="@drawable/ic_baseline_public_24"
android:title="@string/title_discover" />
<item
android:id="@+id/navigation_trending"
android:icon="@drawable/ic_baseline_trending_up_24"
android:title="@string/title_trending" />
<item
android:id="@+id/navigation_most_liked"
android:icon="@drawable/ic_baseline_thumb_up_24"
android:title="@string/title_most_liked" />
android:id="@+id/navigation_local"
android:icon="@drawable/ic_home_black_24dp"
android:title="@string/title_local" />
<item
android:id="@+id/navigation_recently_added"
@ -22,8 +12,14 @@
android:title="@string/title_recently_added" />
<item
android:id="@+id/navigation_local"
android:icon="@drawable/ic_home_black_24dp"
android:title="@string/title_local" />
android:id="@+id/navigation_trending"
android:icon="@drawable/ic_baseline_trending_up_24"
android:title="@string/title_trending" />
<item
android:id="@+id/navigation_discover"
android:icon="@drawable/ic_baseline_public_24"
android:title="@string/title_discover" />
</menu>

View File

@ -2,19 +2,9 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/navigation_discover"
android:icon="@drawable/ic_baseline_public_24"
android:title="@string/title_discover" />
<item
android:id="@+id/navigation_subscription"
android:icon="@drawable/ic_subscription"
android:title="@string/subscriptions" />
<item
android:id="@+id/navigation_trending"
android:icon="@drawable/ic_baseline_trending_up_24"
android:title="@string/title_trending" />
android:id="@+id/navigation_local"
android:icon="@drawable/ic_home_black_24dp"
android:title="@string/title_local" />
<item
android:id="@+id/navigation_recently_added"
@ -22,8 +12,19 @@
android:title="@string/title_recently_added" />
<item
android:id="@+id/navigation_local"
android:icon="@drawable/ic_home_black_24dp"
android:title="@string/title_local" />
android:id="@+id/navigation_trending"
android:icon="@drawable/ic_baseline_trending_up_24"
android:title="@string/title_trending" />
<item
android:id="@+id/navigation_discover"
android:icon="@drawable/ic_baseline_public_24"
android:title="@string/title_discover" />
<item
android:id="@+id/navigation_subscription"
android:icon="@drawable/ic_subscription"
android:title="@string/subscriptions" />
</menu>

View File

@ -8,8 +8,8 @@
android:key="my_account">
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="@string/app_id"
android:targetClass="app.fedilab.fedilabtube.MyAccountActivity" />
android:targetPackage="app.fedilab.fedilabtube.activities"
android:targetClass="app.fedilab.fedilabtube.activities.MyAccountActivity" />
</Preference>
<PreferenceCategory android:title="@string/video_settings">
<androidx.preference.ListPreference

View File

@ -1,3 +1,3 @@
include ':torrentStream'
include ':app'
rootProject.name = "Fedilab Tube"
rootProject.name = "Fedilab Tube"