Add FAB to add new account to account fragment
This commit is contained in:
parent
e6dc6010c7
commit
abfa04064f
|
@ -72,10 +72,6 @@ public class MainActivity extends AppCompatActivity
|
|||
case R.id.action_settings:
|
||||
startActivity(new Intent(getApplicationContext(), SettingsActivity.class));
|
||||
return true;
|
||||
|
||||
case R.id.action_login:
|
||||
startActivity(new Intent(getApplicationContext(), LoginActivity.class));
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.mercury_im.messenger.ui.login;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -8,14 +9,20 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton;
|
||||
|
||||
import org.mercury_im.messenger.MercuryImApplication;
|
||||
import org.mercury_im.messenger.R;
|
||||
import org.mercury_im.messenger.persistence.model.AccountModel;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* A fragment representing a list of Items.
|
||||
* <p/>
|
||||
|
@ -30,7 +37,11 @@ public class AccountsFragment extends Fragment {
|
|||
|
||||
private AccountsRecyclerViewAdapter adapter;
|
||||
|
||||
private RecyclerView recyclerView;
|
||||
@BindView(R.id.list)
|
||||
RecyclerView recyclerView;
|
||||
|
||||
@BindView(R.id.fab)
|
||||
ExtendedFloatingActionButton fab;
|
||||
|
||||
/**
|
||||
* Mandatory empty constructor for the fragment manager to instantiate the
|
||||
|
@ -55,17 +66,17 @@ public class AccountsFragment extends Fragment {
|
|||
Bundle savedInstanceState) {
|
||||
Log.d(MercuryImApplication.TAG, "AccountsFragment.onCreateView");
|
||||
View view = inflater.inflate(R.layout.fragment_account_list, container, false);
|
||||
viewModel = ViewModelProviders.of(this).get(AccountsViewModel.class);
|
||||
ButterKnife.bind(this, view);
|
||||
viewModel = new ViewModelProvider(this).get(AccountsViewModel.class);
|
||||
|
||||
// Set the adapter
|
||||
if (view instanceof RecyclerView) {
|
||||
recyclerView = (RecyclerView) view;
|
||||
Context context = view.getContext();
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(context));
|
||||
this.adapter = new AccountsRecyclerViewAdapter(viewModel, accountClickListener);
|
||||
viewModel.getAccounts().observe(this, roomAccountModels -> adapter.setValues(roomAccountModels));
|
||||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
Context context = view.getContext();
|
||||
|
||||
fab.setOnClickListener(v -> startActivity(new Intent(context, LoginActivity.class)));
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(context));
|
||||
this.adapter = new AccountsRecyclerViewAdapter(viewModel, accountClickListener);
|
||||
viewModel.getAccounts().observe(this, roomAccountModels -> adapter.setValues(roomAccountModels));
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,30 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout 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:id="@+id/list"
|
||||
android:name="org.mercury_im.messenger.ui.login.AccountsFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
app:layoutManager="LinearLayoutManager"
|
||||
tools:context="org.mercury_im.messenger.ui.login.AccountsFragment"
|
||||
tools:listitem="@layout/list_item_account" />
|
||||
android:layout_width="match_parent"
|
||||
android:id="@+id/coordinator">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/list"
|
||||
android:name="org.mercury_im.messenger.ui.login.AccountsFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
app:layoutManager="LinearLayoutManager"
|
||||
tools:context="org.mercury_im.messenger.ui.login.AccountsFragment"
|
||||
tools:listitem="@layout/list_item_account" />
|
||||
|
||||
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton.Icon"
|
||||
android:id="@+id/fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/action_add_account"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="16dp"
|
||||
app:icon="@drawable/ic_add_white_24dp"/>
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
|
|
@ -16,10 +16,4 @@
|
|||
android:orderInCategory="100"
|
||||
android:title="@string/action_settings"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_login"
|
||||
android:orderInCategory="110"
|
||||
android:title="@string/title_activity_login"
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
||||
|
|
|
@ -126,4 +126,5 @@
|
|||
<string name="tab_bookmarks">Bookmarks</string>
|
||||
|
||||
<string name="notification_title">%1$s writes:</string>
|
||||
<string name="action_add_account">Add Account</string>
|
||||
</resources>
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
<item name="colorPrimary">@color/primaryRed</item>
|
||||
<item name="colorSecondary">@color/secondaryBlue</item>
|
||||
<item name="colorOnPrimary">@color/white</item>
|
||||
<item name="colorOnSecondary">@color/white</item>
|
||||
|
||||
<item name="toolbarStyle">@style/Widget.MaterialComponents.Toolbar.Primary</item>
|
||||
<item name="bottomNavigationStyle">@style/Widget.MaterialComponents.BottomNavigationView.PrimarySurface</item>
|
||||
|
|
Loading…
Reference in New Issue