mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-05 20:34:49 +01:00
Setup standard answers, fixes, improvements
This commit is contained in:
@@ -141,6 +141,9 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
|
||||
case R.string.menu_setup:
|
||||
onMenuSetup();
|
||||
break;
|
||||
case R.string.menu_answers:
|
||||
onMenuAnswers();
|
||||
break;
|
||||
case R.string.menu_operations:
|
||||
onMenuOperations();
|
||||
break;
|
||||
@@ -194,6 +197,7 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
|
||||
drawerArray.add(new DrawerItem(R.layout.item_drawer_separator));
|
||||
|
||||
drawerArray.add(new DrawerItem(ActivityView.this, R.layout.item_drawer, R.drawable.baseline_settings_applications_24, R.string.menu_setup));
|
||||
drawerArray.add(new DrawerItem(ActivityView.this, R.layout.item_drawer, R.drawable.baseline_reply_24, R.string.menu_answers));
|
||||
|
||||
if (PreferenceManager.getDefaultSharedPreferences(ActivityView.this).getBoolean("debug", false))
|
||||
drawerArray.add(new DrawerItem(ActivityView.this, R.layout.item_drawer, R.drawable.baseline_list_24, R.string.menu_operations));
|
||||
@@ -428,7 +432,7 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
|
||||
}
|
||||
|
||||
private String getChallenge() throws NoSuchAlgorithmException {
|
||||
String android_id = Settings.System.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
|
||||
String android_id = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
|
||||
return Helper.sha256(android_id);
|
||||
}
|
||||
|
||||
@@ -524,6 +528,12 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
|
||||
startActivity(new Intent(ActivityView.this, ActivitySetup.class));
|
||||
}
|
||||
|
||||
private void onMenuAnswers() {
|
||||
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
||||
fragmentTransaction.replace(R.id.content_frame, new FragmentAnswers()).addToBackStack("answers");
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
|
||||
private void onMenuOperations() {
|
||||
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
||||
fragmentTransaction.replace(R.id.content_frame, new FragmentOperations()).addToBackStack("operations");
|
||||
|
||||
@@ -160,7 +160,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
|
||||
Log.i(Helper.TAG, "Changed @" + position + " #" + count);
|
||||
}
|
||||
});
|
||||
diff.dispatchUpdatesTo(AdapterAccount.this);
|
||||
diff.dispatchUpdatesTo(this);
|
||||
}
|
||||
|
||||
private class MessageDiffCallback extends DiffUtil.Callback {
|
||||
|
||||
168
app/src/main/java/eu/faircode/email/AdapterAnswer.java
Normal file
168
app/src/main/java/eu/faircode/email/AdapterAnswer.java
Normal file
@@ -0,0 +1,168 @@
|
||||
package eu.faircode.email;
|
||||
|
||||
/*
|
||||
This file is part of FairEmail.
|
||||
|
||||
FairEmail is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
NetGuard is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with NetGuard. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2018 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.DiffUtil;
|
||||
import androidx.recyclerview.widget.ListUpdateCallback;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
public class AdapterAnswer extends RecyclerView.Adapter<AdapterAnswer.ViewHolder> {
|
||||
private Context context;
|
||||
|
||||
private List<EntityAnswer> all = new ArrayList<>();
|
||||
private List<EntityAnswer> filtered = new ArrayList<>();
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
View itemView;
|
||||
TextView tvName;
|
||||
|
||||
ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
this.itemView = itemView;
|
||||
tvName = itemView.findViewById(R.id.tvName);
|
||||
}
|
||||
|
||||
private void bindTo(EntityAnswer answer) {
|
||||
tvName.setText(answer.name);
|
||||
}
|
||||
}
|
||||
|
||||
AdapterAnswer(Context context) {
|
||||
this.context = context;
|
||||
setHasStableIds(true);
|
||||
}
|
||||
|
||||
public void set(@NonNull List<EntityAnswer> answers) {
|
||||
Log.i(Helper.TAG, "Set answers=" + answers.size());
|
||||
|
||||
final Collator collator = Collator.getInstance(Locale.getDefault());
|
||||
collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc
|
||||
|
||||
Collections.sort(answers, new Comparator<EntityAnswer>() {
|
||||
@Override
|
||||
public int compare(EntityAnswer a1, EntityAnswer a2) {
|
||||
return collator.compare(a1.name, a2.name);
|
||||
}
|
||||
});
|
||||
|
||||
all.clear();
|
||||
all.addAll(answers);
|
||||
|
||||
DiffUtil.DiffResult diff = DiffUtil.calculateDiff(new MessageDiffCallback(filtered, all));
|
||||
|
||||
filtered.clear();
|
||||
filtered.addAll(all);
|
||||
|
||||
diff.dispatchUpdatesTo(new ListUpdateCallback() {
|
||||
@Override
|
||||
public void onInserted(int position, int count) {
|
||||
Log.i(Helper.TAG, "Inserted @" + position + " #" + count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemoved(int position, int count) {
|
||||
Log.i(Helper.TAG, "Removed @" + position + " #" + count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMoved(int fromPosition, int toPosition) {
|
||||
Log.i(Helper.TAG, "Moved " + fromPosition + ">" + toPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChanged(int position, int count, Object payload) {
|
||||
Log.i(Helper.TAG, "Changed @" + position + " #" + count);
|
||||
}
|
||||
});
|
||||
diff.dispatchUpdatesTo(this);
|
||||
}
|
||||
|
||||
private class MessageDiffCallback extends DiffUtil.Callback {
|
||||
private List<EntityAnswer> prev;
|
||||
private List<EntityAnswer> next;
|
||||
|
||||
MessageDiffCallback(List<EntityAnswer> prev, List<EntityAnswer> next) {
|
||||
this.prev = prev;
|
||||
this.next = next;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOldListSize() {
|
||||
return prev.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNewListSize() {
|
||||
return next.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
|
||||
EntityAnswer a1 = prev.get(oldItemPosition);
|
||||
EntityAnswer a2 = next.get(newItemPosition);
|
||||
return a1.id.equals(a2.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
|
||||
EntityAnswer a1 = prev.get(oldItemPosition);
|
||||
EntityAnswer a2 = next.get(newItemPosition);
|
||||
return a1.equals(a2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return filtered.get(position).id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return filtered.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.item_folder, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||
EntityAnswer answer = filtered.get(position);
|
||||
holder.bindTo(answer);
|
||||
}
|
||||
}
|
||||
@@ -267,7 +267,7 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
|
||||
Log.i(Helper.TAG, "Changed @" + position + " #" + count);
|
||||
}
|
||||
});
|
||||
diff.dispatchUpdatesTo(AdapterAttachment.this);
|
||||
diff.dispatchUpdatesTo(this);
|
||||
}
|
||||
|
||||
private class MessageDiffCallback extends DiffUtil.Callback {
|
||||
|
||||
@@ -218,7 +218,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
|
||||
Log.i(Helper.TAG, "Changed @" + position + " #" + count);
|
||||
}
|
||||
});
|
||||
diff.dispatchUpdatesTo(AdapterFolder.this);
|
||||
diff.dispatchUpdatesTo(this);
|
||||
}
|
||||
|
||||
private class MessageDiffCallback extends DiffUtil.Callback {
|
||||
|
||||
@@ -161,7 +161,7 @@ public class AdapterIdentity extends RecyclerView.Adapter<AdapterIdentity.ViewHo
|
||||
Log.i(Helper.TAG, "Changed @" + position + " #" + count);
|
||||
}
|
||||
});
|
||||
diff.dispatchUpdatesTo(AdapterIdentity.this);
|
||||
diff.dispatchUpdatesTo(this);
|
||||
}
|
||||
|
||||
private class MessageDiffCallback extends DiffUtil.Callback {
|
||||
|
||||
@@ -139,7 +139,7 @@ public class AdapterOperation extends RecyclerView.Adapter<AdapterOperation.View
|
||||
Log.i(Helper.TAG, "Changed @" + position + " #" + count);
|
||||
}
|
||||
});
|
||||
diff.dispatchUpdatesTo(AdapterOperation.this);
|
||||
diff.dispatchUpdatesTo(this);
|
||||
}
|
||||
|
||||
private class MessageDiffCallback extends DiffUtil.Callback {
|
||||
|
||||
@@ -45,14 +45,15 @@ import androidx.sqlite.db.SupportSQLiteDatabase;
|
||||
// https://developer.android.com/topic/libraries/architecture/room.html
|
||||
|
||||
@Database(
|
||||
version = 3,
|
||||
version = 4,
|
||||
entities = {
|
||||
EntityIdentity.class,
|
||||
EntityAccount.class,
|
||||
EntityFolder.class,
|
||||
EntityMessage.class,
|
||||
EntityAttachment.class,
|
||||
EntityOperation.class
|
||||
EntityOperation.class,
|
||||
EntityAnswer.class,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -70,6 +71,8 @@ public abstract class DB extends RoomDatabase {
|
||||
|
||||
public abstract DaoOperation operation();
|
||||
|
||||
public abstract DaoAnswer answer();
|
||||
|
||||
private static DB sInstance;
|
||||
|
||||
private static final String DB_NAME = "email";
|
||||
@@ -125,6 +128,13 @@ public abstract class DB extends RoomDatabase {
|
||||
db.execSQL("ALTER TABLE `identity` ADD COLUMN `store_sent` INTEGER NOT NULL DEFAULT 0");
|
||||
}
|
||||
})
|
||||
.addMigrations(new Migration(3, 4) {
|
||||
@Override
|
||||
public void migrate(SupportSQLiteDatabase db) {
|
||||
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
|
||||
db.execSQL("CREATE TABLE IF NOT EXISTS `answer` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` TEXT NOT NULL, `text` TEXT NOT NULL)");
|
||||
}
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
46
app/src/main/java/eu/faircode/email/DaoAnswer.java
Normal file
46
app/src/main/java/eu/faircode/email/DaoAnswer.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package eu.faircode.email;
|
||||
|
||||
/*
|
||||
This file is part of FairEmail.
|
||||
|
||||
FairEmail is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
NetGuard is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with NetGuard. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2018 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.Query;
|
||||
import androidx.room.Update;
|
||||
|
||||
@Dao
|
||||
public interface DaoAnswer {
|
||||
@Query("SELECT * FROM answer")
|
||||
LiveData<List<EntityAnswer>> liveAnswers();
|
||||
|
||||
@Query("SELECT * FROM answer WHERE id = :id")
|
||||
LiveData<EntityAnswer> liveAnswer(long id);
|
||||
|
||||
@Insert
|
||||
long insertAnswer(EntityAnswer answer);
|
||||
|
||||
@Update
|
||||
int updateAnswer(EntityAnswer answer);
|
||||
|
||||
@Query("DELETE FROM answer WHERE id = :id")
|
||||
void deleteAnswer(long id);
|
||||
}
|
||||
58
app/src/main/java/eu/faircode/email/EntityAnswer.java
Normal file
58
app/src/main/java/eu/faircode/email/EntityAnswer.java
Normal file
@@ -0,0 +1,58 @@
|
||||
package eu.faircode.email;
|
||||
|
||||
/*
|
||||
This file is part of FairEmail.
|
||||
|
||||
FairEmail is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
NetGuard is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with NetGuard. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2018 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.PrimaryKey;
|
||||
|
||||
// https://developer.android.com/training/data-storage/room/defining-data
|
||||
|
||||
@Entity(
|
||||
tableName = EntityAnswer.TABLE_NAME,
|
||||
foreignKeys = {
|
||||
},
|
||||
indices = {
|
||||
}
|
||||
)
|
||||
public class EntityAnswer implements Serializable {
|
||||
static final String TABLE_NAME = "answer";
|
||||
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
public Long id;
|
||||
@NonNull
|
||||
public String name;
|
||||
@NonNull
|
||||
public String text;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof EntityAnswer) {
|
||||
EntityAnswer other = (EntityAnswer) obj;
|
||||
return (this.name.equals(other.name) &&
|
||||
this.text.equals(other.text)
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -126,7 +126,7 @@ public class EntityMessage implements Serializable {
|
||||
BufferedWriter out = null;
|
||||
try {
|
||||
out = new BufferedWriter(new FileWriter(file));
|
||||
out.write(body);
|
||||
out.write(body == null ? "" : body);
|
||||
} finally {
|
||||
if (out != null)
|
||||
try {
|
||||
|
||||
75
app/src/main/java/eu/faircode/email/FragmentAnswer.java
Normal file
75
app/src/main/java/eu/faircode/email/FragmentAnswer.java
Normal file
@@ -0,0 +1,75 @@
|
||||
package eu.faircode.email;
|
||||
|
||||
/*
|
||||
This file is part of FairEmail.
|
||||
|
||||
FairEmail is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
NetGuard is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with NetGuard. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2018 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.constraintlayout.widget.Group;
|
||||
import androidx.lifecycle.Observer;
|
||||
|
||||
public class FragmentAnswer extends FragmentEx {
|
||||
private ViewGroup view;
|
||||
private TextView etName;
|
||||
private TextView etText;
|
||||
private ProgressBar pbWait;
|
||||
private Group grpReady;
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
view = (ViewGroup) inflater.inflate(R.layout.fragment_answer, container, false);
|
||||
|
||||
// Get controls
|
||||
etName = view.findViewById(R.id.etName);
|
||||
etText = view.findViewById(R.id.etText);
|
||||
pbWait = view.findViewById(R.id.pbWait);
|
||||
grpReady = view.findViewById(R.id.grpReady);
|
||||
|
||||
grpReady.setVisibility(View.GONE);
|
||||
pbWait.setVisibility(View.VISIBLE);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(@Nullable final Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
// Get arguments
|
||||
Bundle args = getArguments();
|
||||
long id = (args == null ? -1 : args.getLong("id"));
|
||||
|
||||
DB.getInstance(getContext()).answer().liveAnswer(id).observe(getViewLifecycleOwner(), new Observer<EntityAnswer>() {
|
||||
@Override
|
||||
public void onChanged(EntityAnswer entityAnswer) {
|
||||
|
||||
pbWait.setVisibility(View.GONE);
|
||||
grpReady.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
100
app/src/main/java/eu/faircode/email/FragmentAnswers.java
Normal file
100
app/src/main/java/eu/faircode/email/FragmentAnswers.java
Normal file
@@ -0,0 +1,100 @@
|
||||
package eu.faircode.email;
|
||||
|
||||
/*
|
||||
This file is part of FairEmail.
|
||||
|
||||
FairEmail is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
NetGuard is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with NetGuard. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2018 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.constraintlayout.widget.Group;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
public class FragmentAnswers extends FragmentEx {
|
||||
private RecyclerView rvAnswer;
|
||||
private ProgressBar pbWait;
|
||||
private Group grpReady;
|
||||
private FloatingActionButton fab;
|
||||
|
||||
private AdapterAnswer adapter;
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_answers, container, false);
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
// Get controls
|
||||
rvAnswer = view.findViewById(R.id.rvAnswer);
|
||||
pbWait = view.findViewById(R.id.pbWait);
|
||||
grpReady = view.findViewById(R.id.grpReady);
|
||||
fab = view.findViewById(R.id.fab);
|
||||
|
||||
// Wire controls
|
||||
|
||||
rvAnswer.setHasFixedSize(false);
|
||||
LinearLayoutManager llm = new LinearLayoutManager(getContext());
|
||||
rvAnswer.setLayoutManager(llm);
|
||||
|
||||
adapter = new AdapterAnswer(getContext());
|
||||
rvAnswer.setAdapter(adapter);
|
||||
|
||||
fab.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
|
||||
fragmentTransaction.replace(R.id.content_frame, new FragmentAnswer()).addToBackStack("answer");
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
});
|
||||
|
||||
// Initialize
|
||||
grpReady.setVisibility(View.GONE);
|
||||
pbWait.setVisibility(View.VISIBLE);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
DB db = DB.getInstance(getContext());
|
||||
db.answer().liveAnswers().observe(getViewLifecycleOwner(), new Observer<List<EntityAnswer>>() {
|
||||
@Override
|
||||
public void onChanged(List<EntityAnswer> answers) {
|
||||
adapter.set(answers);
|
||||
pbWait.setVisibility(View.GONE);
|
||||
grpReady.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user