Improve tablet 1

This commit is contained in:
Thomas 2020-07-09 17:57:01 +02:00
parent 9f69c76b6d
commit ceef08db6c
7 changed files with 131 additions and 26 deletions

View File

@ -25,6 +25,7 @@ import android.text.style.ForegroundColorSpan;
import android.text.style.UnderlineSpan; import android.text.style.UnderlineSpan;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
@ -40,6 +41,8 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.google.android.material.textfield.TextInputLayout;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@ -124,10 +127,24 @@ public class LoginActivity extends AppCompatActivity implements OnRetrievePeertu
login_uid = findViewById(R.id.login_uid); login_uid = findViewById(R.id.login_uid);
login_passwd = findViewById(R.id.login_passwd); login_passwd = findViewById(R.id.login_passwd);
if (Helper.isTablet(LoginActivity.this)) {
TextInputLayout login_uid_container = findViewById(R.id.login_uid_container);
ViewGroup.LayoutParams layoutParamsU = login_uid_container.getLayoutParams();
layoutParamsU.width = (int) Helper.convertDpToPixel(300, LoginActivity.this);
login_uid_container.setLayoutParams(layoutParamsU);
TextInputLayout login_passwd_container = findViewById(R.id.login_passwd_container);
ViewGroup.LayoutParams layoutParamsP = login_passwd_container.getLayoutParams();
layoutParamsP.width = (int) Helper.convertDpToPixel(300, LoginActivity.this);
login_passwd_container.setLayoutParams(layoutParamsP);
}
connectionButton = findViewById(R.id.login_button); connectionButton = findViewById(R.id.login_button);
login_uid.setOnFocusChangeListener((v, hasFocus) -> { login_uid.setOnFocusChangeListener((v, hasFocus) -> {
if( !hasFocus) { if (!hasFocus) {
if (android.util.Patterns.EMAIL_ADDRESS.matcher(login_uid.getText().toString().trim()).matches()) { if (android.util.Patterns.EMAIL_ADDRESS.matcher(login_uid.getText().toString().trim()).matches()) {
String[] emailArray = login_uid.getText().toString().split("@"); String[] emailArray = login_uid.getText().toString().split("@");
if (emailArray.length > 1 && Arrays.asList(Helper.openid).contains(emailArray[1])) { if (emailArray.length > 1 && Arrays.asList(Helper.openid).contains(emailArray[1])) {

View File

@ -137,8 +137,7 @@ public class MainActivity extends AppCompatActivity {
intent.putExtras(bundle); intent.putExtras(bundle);
startActivity(intent); startActivity(intent);
return true; return true;
} } else if (item.getItemId() == R.id.action_playlist) {
else if (item.getItemId() == R.id.action_playlist) {
Intent intent = new Intent(MainActivity.this, AllPlaylistsActivity.class); Intent intent = new Intent(MainActivity.this, AllPlaylistsActivity.class);
startActivity(intent); startActivity(intent);
return true; return true;

View File

@ -40,12 +40,12 @@ public class MyVideosActivity extends AppCompatActivity implements OnRetrieveFee
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Bundle b = getIntent().getExtras(); Bundle b = getIntent().getExtras();
if(b != null) if (b != null)
type = (RetrieveFeedsAsyncTask.Type) b.get("type"); type = (RetrieveFeedsAsyncTask.Type) b.get("type");
if( type == RetrieveFeedsAsyncTask.Type.MYVIDEOS) { if (type == RetrieveFeedsAsyncTask.Type.MYVIDEOS) {
setTitle(R.string.my_videos); setTitle(R.string.my_videos);
}else if (type == RetrieveFeedsAsyncTask.Type.PSUBSCRIPTIONS) { } else if (type == RetrieveFeedsAsyncTask.Type.PSUBSCRIPTIONS) {
setTitle(R.string.subscriptions); setTitle(R.string.subscriptions);
} }

View File

@ -48,8 +48,6 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
private List<Peertube> peertubes; private List<Peertube> peertubes;
private Context context; private Context context;
private boolean ownVideos;
public PeertubeAdapter(List<Peertube> peertubes) { public PeertubeAdapter(List<Peertube> peertubes) {
this.peertubes = peertubes; this.peertubes = peertubes;
@ -76,7 +74,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, ""); String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, "");
ownVideos = peertube.getAccount().getInstance().compareTo(Helper.getLiveInstance(context)) == 0 && peertube.getAccount().getId().compareTo(userId) == 0; boolean ownVideos = peertube.getAccount().getInstance().compareTo(Helper.getLiveInstance(context)) == 0 && peertube.getAccount().getId().compareTo(userId) == 0;
holder.peertube_account_name.setText(account.getAcct()); holder.peertube_account_name.setText(account.getAcct());
holder.peertube_title.setText(peertube.getName()); holder.peertube_title.setText(peertube.getName());

View File

@ -16,6 +16,7 @@ package app.fedilab.fedilabtube.fragment;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Rect;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
@ -30,6 +31,7 @@ import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
@ -59,6 +61,7 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
private LinearLayoutManager mLayoutManager; private LinearLayoutManager mLayoutManager;
private GridLayoutManager gLayoutManager;
private boolean flag_loading; private boolean flag_loading;
private Context context; private Context context;
private AsyncTask<Void, Void, Void> asyncTask; private AsyncTask<Void, Void, Void> asyncTask;
@ -126,9 +129,17 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
peertubeAdapater = new PeertubeAdapter(this.peertubes); peertubeAdapater = new PeertubeAdapter(this.peertubes);
lv_status.setAdapter(peertubeAdapater); lv_status.setAdapter(peertubeAdapater);
mLayoutManager = new LinearLayoutManager(context);
lv_status.setLayoutManager(mLayoutManager); if (!Helper.isTablet(context)) {
mLayoutManager = new LinearLayoutManager(context);
lv_status.setLayoutManager(mLayoutManager);
} else {
gLayoutManager = new GridLayoutManager(context, 2);
int spanCount = (int) Helper.convertDpToPixel(2, context);
int spacing = (int) Helper.convertDpToPixel(5, context);
lv_status.addItemDecoration(new GridSpacingItemDecoration(spanCount, spacing, true));
lv_status.setLayoutManager(gLayoutManager);
}
swipeRefreshLayout.setOnRefreshListener(this::pullToRefresh); swipeRefreshLayout.setOnRefreshListener(this::pullToRefresh);
@ -154,23 +165,43 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
if (type != POVERVIEW) { if (type != POVERVIEW) {
lv_status.addOnScrollListener(new RecyclerView.OnScrollListener() { lv_status.addOnScrollListener(new RecyclerView.OnScrollListener() {
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
if (mLayoutManager != null) {
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition(); int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
if (dy > 0) { if (dy > 0) {
int visibleItemCount = mLayoutManager.getChildCount(); int visibleItemCount = mLayoutManager.getChildCount();
int totalItemCount = mLayoutManager.getItemCount(); int totalItemCount = mLayoutManager.getItemCount();
if (firstVisibleItem + visibleItemCount == totalItemCount && context != null) { if (firstVisibleItem + visibleItemCount == totalItemCount && context != null) {
if (!flag_loading) { if (!flag_loading) {
flag_loading = true; flag_loading = true;
if (search_peertube == null) { //Not a Peertube search if (search_peertube == null) { //Not a Peertube search
asyncTask = new RetrieveFeedsAsyncTask(context, type, max_id, DisplayStatusFragment.this).execute(); asyncTask = new RetrieveFeedsAsyncTask(context, type, max_id, DisplayStatusFragment.this).execute();
} else { } else {
asyncTask = new RetrievePeertubeSearchAsyncTask(context, max_id, search_peertube, DisplayStatusFragment.this).execute(); asyncTask = new RetrievePeertubeSearchAsyncTask(context, max_id, search_peertube, DisplayStatusFragment.this).execute();
}
nextElementLoader.setVisibility(View.VISIBLE);
} }
nextElementLoader.setVisibility(View.VISIBLE); } else {
nextElementLoader.setVisibility(View.GONE);
}
}
} else if (gLayoutManager != null) {
int firstVisibleItem = gLayoutManager.findFirstVisibleItemPosition();
if (dy > 0) {
int visibleItemCount = gLayoutManager.getChildCount();
int totalItemCount = gLayoutManager.getItemCount();
if (firstVisibleItem + visibleItemCount == totalItemCount && context != null) {
if (!flag_loading) {
flag_loading = true;
if (search_peertube == null) { //Not a Peertube search
asyncTask = new RetrieveFeedsAsyncTask(context, type, max_id, DisplayStatusFragment.this).execute();
} else {
asyncTask = new RetrievePeertubeSearchAsyncTask(context, max_id, search_peertube, DisplayStatusFragment.this).execute();
}
nextElementLoader.setVisibility(View.VISIBLE);
}
} else {
nextElementLoader.setVisibility(View.GONE);
} }
} else {
nextElementLoader.setVisibility(View.GONE);
} }
} }
} }
@ -289,6 +320,8 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
public void scrollToTop() { public void scrollToTop() {
if (mLayoutManager != null) { if (mLayoutManager != null) {
mLayoutManager.scrollToPositionWithOffset(0, 0); mLayoutManager.scrollToPositionWithOffset(0, 0);
} else if (gLayoutManager != null) {
gLayoutManager.scrollToPositionWithOffset(0, 0);
} }
} }
@ -313,4 +346,40 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
public void onPostAction(int statusCode, PeertubeAPI.StatusAction statusAction, String userId, Error error) { public void onPostAction(int statusCode, PeertubeAPI.StatusAction statusAction, String userId, Error error) {
} }
static class GridSpacingItemDecoration extends RecyclerView.ItemDecoration {
private int spanCount;
private int spacing;
private boolean includeEdge;
public GridSpacingItemDecoration(int spanCount, int spacing, boolean includeEdge) {
this.spanCount = spanCount;
this.spacing = spacing;
this.includeEdge = includeEdge;
}
@Override
public void getItemOffsets(@NotNull Rect outRect, @NotNull View view, RecyclerView parent, @NotNull RecyclerView.State state) {
int position = parent.getChildAdapterPosition(view);
int column = position % spanCount;
if (includeEdge) {
outRect.left = spacing - column * spacing / spanCount;
outRect.right = (column + 1) * spacing / spanCount;
if (position < spanCount) {
outRect.top = spacing;
}
outRect.bottom = spacing;
} else {
outRect.left = column * spacing / spanCount;
outRect.right = spacing - (column + 1) * spacing / spanCount;
if (position >= spanCount) {
outRect.top = spacing;
}
}
}
}
} }

View File

@ -20,6 +20,7 @@ import android.app.DownloadManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Resources;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Color; import android.graphics.Color;
@ -27,6 +28,7 @@ import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.util.DisplayMetrics;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.View; import android.view.View;
import android.view.WindowManager; import android.view.WindowManager;
@ -645,4 +647,23 @@ public class Helper {
return (prefKeyOauthTokenT != null); return (prefKeyOauthTokenT != null);
} }
/**
* Converts dp to pixel
*
* @param dp float - the value in dp to convert
* @param context Context
* @return float - the converted value in pixel
*/
public static float convertDpToPixel(float dp, Context context) {
Resources resources = context.getResources();
DisplayMetrics metrics = resources.getDisplayMetrics();
return dp * ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
}
public static boolean isTablet(Context context) {
return context.getResources().getBoolean(R.bool.is_tablet);
}
} }

View File

@ -20,6 +20,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:divider="?android:dividerHorizontal" android:divider="?android:dividerHorizontal"
android:orientation="vertical" android:orientation="vertical"
android:gravity="bottom"
android:showDividers="end"> android:showDividers="end">
<TextView <TextView