add select activity for multiserver authentication
This commit is contained in:
parent
39b3d11e69
commit
e769131452
9 changed files with 300 additions and 4 deletions
|
|
@ -57,6 +57,10 @@
|
|||
android:name=".activities.LoginActivity"
|
||||
android:label="@string/action_login"
|
||||
android:theme="@style/LoginScreen" />
|
||||
<activity
|
||||
android:name=".activities.SelectActivity"
|
||||
android:label="@string/select"
|
||||
android:theme="@style/LoginScreen" />
|
||||
<activity
|
||||
android:name=".shortcuts.AppShortcutLauncherActivity"
|
||||
android:launchMode="singleInstance"
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ public class LoginActivity extends AbsBaseActivity implements View.OnClickListen
|
|||
|
||||
private void setUpOnClickListeners() {
|
||||
binding.login.setOnClickListener(this);
|
||||
binding.select.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -78,6 +79,11 @@ public class LoginActivity extends AbsBaseActivity implements View.OnClickListen
|
|||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v == binding.select) {
|
||||
startActivity(new Intent(this, SelectActivity.class));
|
||||
return;
|
||||
}
|
||||
|
||||
String username = binding.username.getText().toString().trim();
|
||||
String password = binding.password.getText().toString().trim();
|
||||
String server = binding.server.getText().toString().trim();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,72 @@
|
|||
package com.dkanada.gramophone.activities;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
import com.dkanada.gramophone.App;
|
||||
import com.dkanada.gramophone.R;
|
||||
import com.dkanada.gramophone.activities.base.AbsBaseActivity;
|
||||
import com.dkanada.gramophone.adapter.SelectAdapter;
|
||||
import com.dkanada.gramophone.databinding.ActivitySelectBinding;
|
||||
import com.dkanada.gramophone.model.User;
|
||||
import com.kabouzeid.appthemehelper.ThemeStore;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SelectActivity extends AbsBaseActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Context context = this;
|
||||
ActivitySelectBinding binding = ActivitySelectBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
|
||||
List<User> users = App.getDatabase().userDao().getUsers();
|
||||
SelectAdapter adapter = new SelectAdapter(this, users);
|
||||
|
||||
binding.recyclerView.setAdapter(adapter);
|
||||
binding.recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
|
||||
binding.add.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startActivity(new Intent(context, LoginActivity.class));
|
||||
}
|
||||
});
|
||||
|
||||
setDrawUnderStatusbar();
|
||||
setStatusbarColorAuto();
|
||||
|
||||
setNavigationbarColorAuto();
|
||||
setTaskDescriptionColorAuto();
|
||||
|
||||
int primaryColor = ThemeStore.primaryColor(this);
|
||||
|
||||
binding.add.setBackgroundColor(primaryColor);
|
||||
binding.toolbar.setBackgroundColor(primaryColor);
|
||||
setSupportActionBar(binding.toolbar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
overridePendingTransition(0, R.anim.fade_quick);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
onBackPressed();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
package com.dkanada.gramophone.adapter;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.dkanada.gramophone.App;
|
||||
import com.dkanada.gramophone.R;
|
||||
import com.dkanada.gramophone.activities.SplashActivity;
|
||||
import com.dkanada.gramophone.model.User;
|
||||
import com.dkanada.gramophone.util.PreferenceUtil;
|
||||
import com.dkanada.gramophone.views.IconImageView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SelectAdapter extends RecyclerView.Adapter<SelectAdapter.ViewHolder> {
|
||||
private final AppCompatActivity activity;
|
||||
private final List<User> users;
|
||||
|
||||
public SelectAdapter(@NonNull AppCompatActivity activity, List<User> users) {
|
||||
this.activity = activity;
|
||||
this.users = users;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(activity).inflate(R.layout.card_server, parent, false);
|
||||
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||
final User user = users.get(position);
|
||||
|
||||
holder.name.setText(user.name);
|
||||
holder.url.setText(user.server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return users.size();
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView name;
|
||||
TextView url;
|
||||
|
||||
IconImageView delete;
|
||||
IconImageView select;
|
||||
|
||||
public ViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
|
||||
name = itemView.findViewById(R.id.name);
|
||||
url = itemView.findViewById(R.id.url);
|
||||
delete = itemView.findViewById(R.id.delete);
|
||||
select = itemView.findViewById(R.id.select);
|
||||
|
||||
delete.setOnClickListener(this::onDelete);
|
||||
select.setOnClickListener(this::onSelect);
|
||||
}
|
||||
|
||||
public void onSelect(View v) {
|
||||
final User user = users.get(getBindingAdapterPosition());
|
||||
|
||||
PreferenceUtil.getInstance(activity).setServer(user.server);
|
||||
PreferenceUtil.getInstance(activity).setUser(user.id);
|
||||
|
||||
activity.startActivity(new Intent(activity, SplashActivity.class));
|
||||
}
|
||||
|
||||
public void onDelete(View v) {
|
||||
final User user = users.get(getBindingAdapterPosition());
|
||||
|
||||
App.getDatabase().userDao().deleteUser(user);
|
||||
users.remove(user);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
5
app/src/main/res/drawable/card_server.xml
Normal file
5
app/src/main/res/drawable/card_server.xml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="?cardBackgroundColor"/>
|
||||
<corners android:radius="8dp"/>
|
||||
</shape>
|
||||
|
|
@ -4,11 +4,9 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:context=".activities.LoginActivity">
|
||||
|
||||
<include layout="@layout/status_bar"
|
||||
android:id="@+id/status_bar"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
|
@ -127,11 +125,28 @@
|
|||
android:id="@+id/login"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="64dp"
|
||||
android:layout_margin="32dp"
|
||||
android:layout_marginHorizontal="32dp"
|
||||
android:layout_marginTop="32dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:text="@string/login"
|
||||
app:cornerRadius="24dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent" />
|
||||
app:layout_constraintBottom_toTopOf="@id/select" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/select"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="64dp"
|
||||
android:layout_marginHorizontal="32dp"
|
||||
android:layout_marginTop="0dp"
|
||||
android:layout_marginBottom="32dp"
|
||||
android:text="@string/select"
|
||||
android:backgroundTint="?cardBackgroundColor"
|
||||
app:cornerRadius="24dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
tools:ignore="UnusedAttribute" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
|
|||
46
app/src/main/res/layout/activity_select.xml
Normal file
46
app/src/main/res/layout/activity_select.xml
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
<?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="match_parent"
|
||||
tools:context=".activities.SelectActivity">
|
||||
|
||||
<include layout="@layout/status_bar"
|
||||
android:id="@+id/status_bar"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
style="@style/Toolbar"
|
||||
android:id="@+id/toolbar"
|
||||
android:background="@android:color/transparent"
|
||||
app:layout_constraintTop_toBottomOf="@id/status_bar"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginVertical="20dp"
|
||||
android:scrollbars="vertical"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toTopOf="@id/add"
|
||||
app:layout_constraintTop_toBottomOf="@id/toolbar" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/add"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="64dp"
|
||||
android:layout_margin="32dp"
|
||||
android:text="@string/add"
|
||||
app:cornerRadius="24dp"
|
||||
app:backgroundTint="?colorPrimary"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
58
app/src/main/res/layout/card_server.xml
Normal file
58
app/src/main/res/layout/card_server.xml
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:layout_margin="20dp"
|
||||
android:background="@drawable/card_server"
|
||||
android:elevation="4dp"
|
||||
tools:ignore="UnusedAttribute">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="20dp"
|
||||
android:paddingEnd="20dp"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/delete"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Headline"
|
||||
tools:text="Server" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/url"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
||||
android:textColor="?android:textColorSecondary"
|
||||
tools:text="https://jellyfin.org" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<com.dkanada.gramophone.views.IconImageView
|
||||
android:id="@+id/delete"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/select"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:srcCompat="@drawable/ic_delete_white_24dp"
|
||||
style="@style/OverFlowButton" />
|
||||
|
||||
<com.dkanada.gramophone.views.IconImageView
|
||||
android:id="@+id/select"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:srcCompat="@drawable/ic_keyboard_arrow_right_white_24dp"
|
||||
style="@style/OverFlowButton" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
@ -187,6 +187,8 @@
|
|||
<string name="widget_classic">Classic</string>
|
||||
<string name="widget_card">Card</string>
|
||||
|
||||
<string name="select">Select</string>
|
||||
<string name="add">Add</string>
|
||||
<string name="login">Login</string>
|
||||
<string name="disable">Disable</string>
|
||||
<string name="ignore">Ignore</string>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue