1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2025-01-13 03:07:32 +01:00

Controllable backgroundColor to item view. Split lines Activity Kind and Activity Name Label to prevent overflow

This commit is contained in:
vanous 2020-08-26 20:45:38 +02:00
parent 3bf2d4f086
commit 723bd6fb6e
5 changed files with 39 additions and 16 deletions

View File

@ -23,9 +23,11 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Resources;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.util.SparseBooleanArray; import android.util.SparseBooleanArray;
import android.util.TypedValue;
import android.view.ActionMode; import android.view.ActionMode;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -259,8 +261,10 @@ public class ActivitySummariesActivity extends AbstractListActivity<BaseActivity
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filterLocal); LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filterLocal);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
ActivitySummariesAdapter activitySummariesAdapter = new ActivitySummariesAdapter(this, mGBDevice,activityFilter,dateFromFilter,dateToFilter,nameContainsFilter);
setItemAdapter(new ActivitySummariesAdapter(this, mGBDevice,activityFilter,dateFromFilter,dateToFilter,nameContainsFilter)); int backgroundColor = getBackgroundColor(ActivitySummariesActivity.this);
activitySummariesAdapter.setBackgroundColor(backgroundColor);
setItemAdapter(activitySummariesAdapter);
getItemListView().setOnItemClickListener(new AdapterView.OnItemClickListener() { getItemListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override @Override
@ -465,6 +469,11 @@ public class ActivitySummariesActivity extends AbstractListActivity<BaseActivity
} }
public static int getBackgroundColor(Context context) {
TypedValue typedValue = new TypedValue();
Resources.Theme theme = context.getTheme();
theme.resolveAttribute(R.attr.sports_activity_summary_background, typedValue, true);
return typedValue.data;
}
} }

View File

@ -242,6 +242,12 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
TextView activity_name = findViewById(R.id.activityname); TextView activity_name = findViewById(R.id.activityname);
activity_name.setText(activityname); activity_name.setText(activityname);
if (activityname == null || (activityname != null && activityname.length() < 1)) {
activity_name.setVisibility(View.GONE);
} else {
activity_name.setVisibility(View.VISIBLE);
}
TextView start_time = findViewById(R.id.starttime); TextView start_time = findViewById(R.id.starttime);
start_time.setText(starttimeS); start_time.setText(starttimeS);
TextView end_time = findViewById(R.id.endtime); TextView end_time = findViewById(R.id.endtime);

View File

@ -18,6 +18,8 @@
package nodomain.freeyourgadget.gadgetbridge.adapter; package nodomain.freeyourgadget.gadgetbridge.adapter;
import android.content.Context; import android.content.Context;
import android.content.res.Resources;
import android.util.TypedValue;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -25,10 +27,11 @@ import android.widget.ArrayAdapter;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.DrawableRes;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import androidx.annotation.DrawableRes;
import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.R;
/** /**
@ -43,6 +46,7 @@ public abstract class AbstractItemAdapter<T> extends ArrayAdapter<T> {
private final List<T> items; private final List<T> items;
private boolean horizontalAlignment; private boolean horizontalAlignment;
private int size = SIZE_MEDIUM; private int size = SIZE_MEDIUM;
private int backgroundColor=0;
public AbstractItemAdapter(Context context) { public AbstractItemAdapter(Context context) {
this (context, new ArrayList<T>()); this (context, new ArrayList<T>());
@ -103,6 +107,7 @@ public abstract class AbstractItemAdapter<T> extends ArrayAdapter<T> {
nameView.setText(getName(item)); nameView.setText(getName(item));
detailsView.setText(getDetails(item)); detailsView.setText(getDetails(item));
iconView.setImageResource(getIcon(item)); iconView.setImageResource(getIcon(item));
iconView.setBackgroundColor(backgroundColor);
return view; return view;
} }
@ -118,10 +123,12 @@ public abstract class AbstractItemAdapter<T> extends ArrayAdapter<T> {
this.size = size; this.size = size;
} }
public void setBackgroundColor(int backgroundColor) {
this.backgroundColor = backgroundColor;
}
public int getSize() { public int getSize() {
return size; return size;
} }
public List<T> getItems() { public List<T> getItems() {
return items; return items;
} }
@ -136,4 +143,5 @@ public abstract class AbstractItemAdapter<T> extends ArrayAdapter<T> {
notifyDataSetChanged(); notifyDataSetChanged();
} }
} }
} }

View File

@ -48,21 +48,13 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:fontFamily="sans-serif-black" android:fontFamily="sans-serif-black"
android:maxLines="1" android:maxLines="1"
android:paddingEnd="10dp"
android:scrollHorizontally="false"
android:textSize="18sp" />
<TextView
android:id="@+id/activityname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-black"
android:maxLines="1"
android:scrollHorizontally="false" android:scrollHorizontally="false"
android:textSize="18sp" /> android:textSize="18sp" />
<View <View
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="1dp" android:layout_height="1dp"
android:layout_weight="1" /> android:layout_weight="0.1" />
<ImageView <ImageView
android:id="@+id/activity_summary_detail_edit_name" android:id="@+id/activity_summary_detail_edit_name"
@ -74,6 +66,15 @@
app:srcCompat="@drawable/ic_edit" /> app:srcCompat="@drawable/ic_edit" />
</LinearLayout> </LinearLayout>
<TextView
android:id="@+id/activityname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-black"
android:scrollHorizontally="false"
android:singleLine="true"
android:textSize="18sp" />
<TableLayout <TableLayout
android:id="@+id/summaryHeader" android:id="@+id/summaryHeader"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -8,7 +8,6 @@
android:layout_width="56dp" android:layout_width="56dp"
android:layout_height="56dp" android:layout_height="56dp"
android:layout_alignParentStart="true" android:layout_alignParentStart="true"
android:background="?attr/sports_activity_summary_background"
android:contentDescription="@string/candidate_item_device_image" android:contentDescription="@string/candidate_item_device_image"
android:padding="8dp" /> android:padding="8dp" />