Updater: initial layout for TV

Change-Id: Ia4704f7a15d9c1179ec93c1cab28707ba8115e70
This commit is contained in:
Timi Rautamäki
2021-08-29 17:08:33 +00:00
parent 6e5bbdaae1
commit a96d54f236
3 changed files with 220 additions and 39 deletions

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/inverted"
android:pathData="M12,15.5A3.5,3.5 0 0,1 8.5,12A3.5,3.5 0 0,1 12,8.5A3.5,3.5 0 0,1 15.5,12A3.5,3.5 0 0,1 12,15.5M19.43,12.97C19.47,12.65 19.5,12.33 19.5,12C19.5,11.67 19.47,11.34 19.43,11L21.54,9.37C21.73,9.22 21.78,8.95 21.66,8.73L19.66,5.27C19.54,5.05 19.27,4.96 19.05,5.05L16.56,6.05C16.04,5.66 15.5,5.32 14.87,5.07L14.5,2.42C14.46,2.18 14.25,2 14,2H10C9.75,2 9.54,2.18 9.5,2.42L9.13,5.07C8.5,5.32 7.96,5.66 7.44,6.05L4.95,5.05C4.73,4.96 4.46,5.05 4.34,5.27L2.34,8.73C2.21,8.95 2.27,9.22 2.46,9.37L4.57,11C4.53,11.34 4.5,11.67 4.5,12C4.5,12.33 4.53,12.65 4.57,12.97L2.46,14.63C2.27,14.78 2.21,15.05 2.34,15.27L4.34,18.73C4.46,18.95 4.73,19.03 4.95,18.95L7.44,17.94C7.96,18.34 8.5,18.68 9.13,18.93L9.5,21.58C9.54,21.82 9.75,22 10,22H14C14.25,22 14.46,21.82 14.5,21.58L14.87,18.93C15.5,18.67 16.04,18.34 16.56,17.94L19.05,18.95C19.27,19.03 19.54,18.95 19.66,18.73L21.66,15.27C21.78,15.05 21.73,14.78 21.54,14.63L19.43,12.97Z" />
</vector>

View File

@@ -0,0 +1,129 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:id="@+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:padding="16dp"
android:weightSum="2">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingEnd="16dp"
android:paddingStart="16dp"
android:layout_gravity="start">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/header_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:paddingBottom="16dp"
android:textColor="?android:attr/textColorPrimary"
android:textSize="56sp" />
<TextView
android:id="@+id/header_build_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/header_title"
android:textColor="?android:attr/textColorPrimary"
android:textSize="14sp" />
<TextView
android:id="@+id/header_build_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/header_build_version"
android:textColor="?android:attr/textColorPrimary"
android:textSize="14sp" />
<TextView
android:id="@+id/header_last_check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/header_build_date"
android:textColor="?android:attr/textColorPrimary"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/header_last_check"
android:layout_alignParentBottom="true"
android:weightSum="2"
android:orientation="horizontal">
<Button
android:id="@+id/refresh"
android:drawableLeft="@drawable/ic_menu_refresh"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="refresh"
style="@style/Widget.AppCompat.Button.Borderless.Colored"/>
<Button
android:id="@+id/preferences"
android:drawableLeft="@drawable/ic_menu_preferences"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="preferences"
style="@style/Widget.AppCompat.Button.Borderless.Colored"/>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingEnd="16dp"
android:paddingStart="16dp"
android:layout_gravity="end">
<androidx.core.widget.NestedScrollView
android:id="@+id/no_new_updates_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="46dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/list_no_updates"
android:textColor="?android:textColorSecondary" />
</androidx.core.widget.NestedScrollView>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="12dp"
android:clipToPadding="false"
android:paddingBottom="5dp"
android:scrollbars="vertical"
android:layout_gravity="end" />
<ProgressBar
android:id="@+id/refresh_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="gone"/>
</RelativeLayout>
</LinearLayout>

View File

@@ -15,11 +15,13 @@
*/ */
package org.lineageos.updater; package org.lineageos.updater;
import android.app.UiModeManager;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.res.Configuration;
import android.content.ServiceConnection; import android.content.ServiceConnection;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.icu.text.DateFormat; import android.icu.text.DateFormat;
@@ -37,12 +39,14 @@ import android.view.View;
import android.view.animation.Animation; import android.view.animation.Animation;
import android.view.animation.LinearInterpolator; import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation; import android.view.animation.RotateAnimation;
import android.widget.Button;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.Switch; import android.widget.Switch;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
@@ -81,11 +85,16 @@ public class UpdatesActivity extends UpdatesListActivity {
private View mRefreshIconView; private View mRefreshIconView;
private RotateAnimation mRefreshAnimation; private RotateAnimation mRefreshAnimation;
private boolean mIsTV;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_updates); setContentView(R.layout.activity_updates);
UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
mIsTV = uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION;
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view); RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
mAdapter = new UpdatesListAdapter(this); mAdapter = new UpdatesListAdapter(this);
recyclerView.setAdapter(mAdapter); recyclerView.setAdapter(mAdapter);
@@ -114,10 +123,12 @@ public class UpdatesActivity extends UpdatesListActivity {
} }
}; };
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); if (!mIsTV) {
setSupportActionBar(toolbar); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false); setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
TextView headerTitle = (TextView) findViewById(R.id.header_title); TextView headerTitle = (TextView) findViewById(R.id.header_title);
headerTitle.setText(getString(R.string.header_title_text, headerTitle.setText(getString(R.string.header_title_text,
@@ -133,35 +144,50 @@ public class UpdatesActivity extends UpdatesListActivity {
headerBuildDate.setText(StringGenerator.getDateLocalizedUTC(this, headerBuildDate.setText(StringGenerator.getDateLocalizedUTC(this,
DateFormat.LONG, BuildInfoUtils.getBuildDateTimestamp())); DateFormat.LONG, BuildInfoUtils.getBuildDateTimestamp()));
// Switch between header title and appbar title minimizing overlaps if (!mIsTV) {
final CollapsingToolbarLayout collapsingToolbar = // Switch between header title and appbar title minimizing overlaps
(CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); final CollapsingToolbarLayout collapsingToolbar =
final AppBarLayout appBar = (AppBarLayout) findViewById(R.id.app_bar); (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
appBar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { final AppBarLayout appBar = (AppBarLayout) findViewById(R.id.app_bar);
boolean mIsShown = false; appBar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
boolean mIsShown = false;
@Override @Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
int scrollRange = appBarLayout.getTotalScrollRange(); int scrollRange = appBarLayout.getTotalScrollRange();
if (!mIsShown && scrollRange + verticalOffset < 10) { if (!mIsShown && scrollRange + verticalOffset < 10) {
collapsingToolbar.setTitle(getString(R.string.display_name)); collapsingToolbar.setTitle(getString(R.string.display_name));
mIsShown = true; mIsShown = true;
} else if (mIsShown && scrollRange + verticalOffset > 100) { } else if (mIsShown && scrollRange + verticalOffset > 100) {
collapsingToolbar.setTitle(null); collapsingToolbar.setTitle(null);
mIsShown = false; mIsShown = false;
}
} }
});
mRefreshAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
mRefreshAnimation.setInterpolator(new LinearInterpolator());
mRefreshAnimation.setDuration(1000);
if (!Utils.hasTouchscreen(this)) {
// This can't be collapsed without a touchscreen
appBar.setExpanded(false);
} }
}); } else {
findViewById(R.id.refresh).setOnClickListener(new View.OnClickListener() {
if (!Utils.hasTouchscreen(this)) { @Override
// This can't be collapsed without a touchscreen public void onClick(View v) {
appBar.setExpanded(false); downloadUpdatesList(true);
}
});
findViewById(R.id.preferences).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showPreferencesDialog();
}
});
} }
mRefreshAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
mRefreshAnimation.setInterpolator(new LinearInterpolator());
mRefreshAnimation.setDuration(1000);
} }
@Override @Override
@@ -393,20 +419,35 @@ public class UpdatesActivity extends UpdatesListActivity {
} }
private void refreshAnimationStart() { private void refreshAnimationStart() {
if (mRefreshIconView == null) { if (!mIsTV) {
mRefreshIconView = findViewById(R.id.menu_refresh); if (mRefreshIconView == null) {
} mRefreshIconView = findViewById(R.id.menu_refresh);
if (mRefreshIconView != null) { }
mRefreshAnimation.setRepeatCount(Animation.INFINITE); if (mRefreshIconView != null) {
mRefreshIconView.startAnimation(mRefreshAnimation); mRefreshAnimation.setRepeatCount(Animation.INFINITE);
mRefreshIconView.setEnabled(false); mRefreshIconView.startAnimation(mRefreshAnimation);
mRefreshIconView.setEnabled(false);
}
} else {
findViewById(R.id.recycler_view).setVisibility(View.GONE);
findViewById(R.id.no_new_updates_view).setVisibility(View.GONE);
findViewById(R.id.refresh_progress).setVisibility(View.VISIBLE);
} }
} }
private void refreshAnimationStop() { private void refreshAnimationStop() {
if (mRefreshIconView != null) { if (!mIsTV) {
mRefreshAnimation.setRepeatCount(0); if (mRefreshIconView != null) {
mRefreshIconView.setEnabled(true); mRefreshAnimation.setRepeatCount(0);
mRefreshIconView.setEnabled(true);
}
} else {
findViewById(R.id.refresh_progress).setVisibility(View.GONE);
if (mAdapter.getItemCount() > 0) {
findViewById(R.id.recycler_view).setVisibility(View.VISIBLE);
} else {
findViewById(R.id.no_new_updates_view).setVisibility(View.VISIBLE);
}
} }
} }