Merge pull request #246 from cyb3rko/compact-message-layout

Compact message layout
This commit is contained in:
Jannis Mattheis
2022-10-10 19:39:36 +00:00
committed by GitHub
20 changed files with 158 additions and 18 deletions

View File

@@ -34,11 +34,13 @@ import org.threeten.bp.OffsetDateTime;
public class ListMessageAdapter extends RecyclerView.Adapter<ListMessageAdapter.ViewHolder> {
private Context context;
private SharedPreferences prefs;
private Picasso picasso;
private List<MessageWithImage> items;
private Delete delete;
private Settings settings;
private Markwon markwon;
private int messageLayout;
private final String TIME_FORMAT_RELATIVE;
private final String TIME_FORMAT_PREFS_KEY;
@@ -56,11 +58,25 @@ public class ListMessageAdapter extends RecyclerView.Adapter<ListMessageAdapter.
this.items = items;
this.delete = delete;
this.prefs = PreferenceManager.getDefaultSharedPreferences(context);
this.markwon = MarkwonFactory.createForMessage(context, picasso);
TIME_FORMAT_RELATIVE =
context.getResources().getString(R.string.time_format_value_relative);
TIME_FORMAT_PREFS_KEY = context.getResources().getString(R.string.setting_key_time_format);
String message_layout_prefs_key =
context.getResources().getString(R.string.setting_key_message_layout);
String messageLayoutNormal =
context.getResources().getString(R.string.message_layout_value_normal);
String messageLayoutSetting =
prefs.getString(message_layout_prefs_key, messageLayoutNormal);
if (messageLayoutSetting.equals(messageLayoutNormal)) {
messageLayout = R.layout.message_item;
} else {
messageLayout = R.layout.message_item_compact;
}
}
public List<MessageWithImage> getItems() {
@@ -74,7 +90,7 @@ public class ListMessageAdapter extends RecyclerView.Adapter<ListMessageAdapter.
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.message_item, parent, false);
View view = LayoutInflater.from(context).inflate(messageLayout, parent, false);
ViewHolder holder = new ViewHolder(view);
return holder;

View File

@@ -1,11 +1,18 @@
package com.github.gotify.settings;
import android.app.AlertDialog;
import android.content.ComponentName;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.ListPreference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceManager;
import com.github.gotify.R;
@@ -52,5 +59,38 @@ public class SettingsActivity extends AppCompatActivity
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.root_preferences, rootKey);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ListPreference message_layout =
findPreference(getString(R.string.setting_key_message_layout));
message_layout.setOnPreferenceChangeListener(
(ignored, ignored2) -> {
new AlertDialog.Builder(getContext())
.setTitle(R.string.setting_message_layout_dialog_title)
.setMessage(R.string.setting_message_layout_dialog_message)
.setPositiveButton(
getString(R.string.setting_message_layout_dialog_button1),
(ignored3, ignored4) -> {
restartApp();
})
.setNegativeButton(
getString(R.string.setting_message_layout_dialog_button2),
(ignore3, ignored4) -> {})
.show();
return true;
});
}
private void restartApp() {
PackageManager packageManager = getContext().getPackageManager();
String packageName = getContext().getPackageName();
Intent intent = packageManager.getLaunchIntentForPackage(packageName);
ComponentName componentName = intent.getComponent();
Intent mainIntent = Intent.makeRestartActivityTask(componentName);
startActivity(mainIntent);
Runtime.getRuntime().exit(0);
}
}
}

View File

@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
@@ -12,7 +13,7 @@
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_marginEnd="8dp"
android:text=""
tools:text="1 hour ago"
app:layout_constraintEnd_toStartOf="@+id/message_delete"
app:layout_constraintTop_toTopOf="parent" />
@@ -22,7 +23,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:text=""
tools:text="A Notification Title"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="@+id/message_date"
@@ -35,11 +36,11 @@
android:layout_height="50dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
tools:srcCompat="@drawable/gotify"
android:contentDescription="@string/message_image_desc"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/message_title" />
<TextView
android:id="@+id/message_text"
android:layout_width="0dp"
@@ -48,6 +49,7 @@
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:textIsSelectable="true"
tools:text="The message text."
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/message_image"
app:layout_constraintTop_toBottomOf="@+id/message_title" />

View File

@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp"
android:background="?android:colorBackground">
<TextView
android:id="@+id/message_date"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_marginEnd="8dp"
tools:text="1 hour ago"
app:layout_constraintEnd_toStartOf="@+id/message_delete"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/message_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
tools:text="A Notification Title"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="@+id/message_date"
app:layout_constraintStart_toEndOf="@id/message_image"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/message_image"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginStart="0dp"
android:layout_marginTop="0dp"
tools:src="@drawable/gotify"
android:contentDescription="@string/message_image_desc"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
<TextView
android:id="@+id/message_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="3dp"
android:layout_marginEnd="8dp"
android:textIsSelectable="true"
tools:text="The message text."
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/message_image"
app:layout_constraintTop_toBottomOf="@+id/message_title" />
<ImageButton
android:id="@+id/message_delete"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="30dp"
android:layout_height="30dp"
android:contentDescription="@string/delete_message"
app:layout_constraintBottom_toBottomOf="@+id/message_date"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_delete" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -8,6 +8,19 @@
<string name="theme_light">Light</string>
<string name="theme_dark">Dark</string>
<string name="theme_default">System Default</string>
<!-- Message Layout -->
<string-array name="message_layout_entries">
<item>@string/message_layout_entry_normal</item>
<item>@string/message_layout_entry_compact</item>
</string-array>
<string name="message_layout_entry_normal">Normal</string>
<string name="message_layout_entry_compact">Compact</string>
<string-array name="message_layout_values">
<item>@string/message_layout_value_normal</item>
<item>@string/message_layout_value_compact</item>
</string-array>
<string name="message_layout_value_normal">message_layout_normal</string>
<string name="message_layout_value_compact">message_layout_compact</string>
<!-- Time Format -->
<string-array name="time_format_entries">
<item>@string/time_format_entry_absolute</item>

View File

@@ -70,6 +70,12 @@
<string name="settings_appearance">Appearance</string>
<string name="setting_theme">Theme</string>
<string name="setting_key_theme">theme</string>
<string name="setting_message_layout">Message layout</string>
<string name="setting_key_message_layout">message_layout</string>
<string name="setting_message_layout_dialog_title">Restart App?</string>
<string name="setting_message_layout_dialog_message">The change will be effective on next app start.\n\nDo you want to restart now?</string>
<string name="setting_message_layout_dialog_button1">Restart</string>
<string name="setting_message_layout_dialog_button2">Later</string>
<string name="setting_time_format">Time format</string>
<string name="setting_key_time_format">time_format</string>
<string name="push_message">Push message</string>

View File

@@ -9,6 +9,13 @@
android:key="@string/setting_key_theme"
android:title="@string/setting_theme" />
<ListPreference
android:defaultValue="@string/message_layout_value_normal"
android:entries="@array/message_layout_entries"
android:entryValues="@array/message_layout_values"
android:key="@string/setting_key_message_layout"
android:title="@string/setting_message_layout" />
<ListPreference
android:defaultValue="@string/time_format_value_relative"
android:entries="@array/time_format_entries"

View File

@@ -13,7 +13,6 @@
package com.github.gotify.client;
@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2020-06-24T18:39:01.386+02:00")
public class StringUtil {
/**
* Check if the given array contains the given value (with case-insensitive comparison).

View File

@@ -27,7 +27,6 @@ import java.io.IOException;
* The Application holds information about an app which can send notifications.
*/
@ApiModel(description = "The Application holds information about an app which can send notifications.")
@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2020-06-24T18:39:01.386+02:00")
public class Application {
@SerializedName("description")
private String description = null;

View File

@@ -27,7 +27,6 @@ import java.io.IOException;
* The Client holds information about a device which can receive notifications (and other stuff).
*/
@ApiModel(description = "The Client holds information about a device which can receive notifications (and other stuff).")
@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2020-06-24T18:39:01.386+02:00")
public class Client {
@SerializedName("id")
private Long id = null;

View File

@@ -27,7 +27,6 @@ import java.io.IOException;
* The Error contains error relevant information.
*/
@ApiModel(description = "The Error contains error relevant information.")
@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2020-06-24T18:39:01.386+02:00")
public class Error {
@SerializedName("error")
private String error = null;

View File

@@ -27,7 +27,6 @@ import java.io.IOException;
* Health represents how healthy the application is.
*/
@ApiModel(description = "Health represents how healthy the application is.")
@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2020-06-24T18:39:01.386+02:00")
public class Health {
@SerializedName("database")
private String database = null;

View File

@@ -31,7 +31,6 @@ import org.threeten.bp.OffsetDateTime;
* The MessageExternal holds information about a message which was sent by an Application.
*/
@ApiModel(description = "The MessageExternal holds information about a message which was sent by an Application.")
@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2020-06-24T18:39:01.386+02:00")
public class Message {
@SerializedName("appid")
private Long appid = null;

View File

@@ -31,7 +31,6 @@ import java.util.List;
* Wrapper for the paging and the messages
*/
@ApiModel(description = "Wrapper for the paging and the messages")
@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2020-06-24T18:39:01.386+02:00")
public class PagedMessages {
@SerializedName("messages")
private List<Message> messages = new ArrayList<Message>();

View File

@@ -27,7 +27,6 @@ import java.io.IOException;
* The Paging holds information about the limit and making requests to the next page.
*/
@ApiModel(description = "The Paging holds information about the limit and making requests to the next page.")
@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2020-06-24T18:39:01.386+02:00")
public class Paging {
@SerializedName("limit")
private Long limit = null;

View File

@@ -29,7 +29,6 @@ import java.util.List;
* Holds information about a plugin instance for one user.
*/
@ApiModel(description = "Holds information about a plugin instance for one user.")
@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2020-06-24T18:39:01.386+02:00")
public class PluginConf {
@SerializedName("author")
private String author = null;

View File

@@ -27,7 +27,6 @@ import java.io.IOException;
* The User holds information about permission and other stuff.
*/
@ApiModel(description = "The User holds information about permission and other stuff.")
@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2020-06-24T18:39:01.386+02:00")
public class User {
@SerializedName("admin")
private Boolean admin = null;

View File

@@ -27,7 +27,6 @@ import java.io.IOException;
* The Password for updating the user.
*/
@ApiModel(description = "The Password for updating the user.")
@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2020-06-24T18:39:01.386+02:00")
public class UserPass {
@SerializedName("pass")
private String pass = null;

View File

@@ -27,7 +27,6 @@ import java.io.IOException;
* The UserWithPass holds information about the credentials and other stuff.
*/
@ApiModel(description = "The UserWithPass holds information about the credentials and other stuff.")
@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2020-06-24T18:39:01.386+02:00")
public class UserWithPass {
@SerializedName("admin")
private Boolean admin = null;

View File

@@ -27,7 +27,6 @@ import java.io.IOException;
* VersionInfo Model
*/
@ApiModel(description = "VersionInfo Model")
@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2020-06-24T18:39:01.386+02:00")
public class VersionInfo {
@SerializedName("buildDate")
private String buildDate = null;