Привет, ребята, это приложение-напоминание, в котором я могу добавить информацию и установить ее на главной странице и сохранить информацию в базе данных, но, тем не менее, я не уверен, как реализовать таймер, который пользователь может установить и получать уведомления, когда готово. Я могу отправить файл, если необходимо.
MainActivity
public class MainActivity2 extends AppCompatActivity {
TextView titlepage, subtitlepage, endpage;
Button btnAddNew;
DatabaseReference reference;
RecyclerView ourdoes;
ArrayList<MyDoes> list;
DoesAdapter doesAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
titlepage = findViewById(R.id.titlepage);
subtitlepage = findViewById(R.id.subtitlepage);
endpage = findViewById(R.id.endpage);
btnAddNew = findViewById(R.id.btnAddNew);
// import font
// btnAddNew.setTypeface(MLight);
btnAddNew.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent a = new Intent(MainActivity2.this,NewTaskAct.class);
startActivity(a);
}
});
// working with data
ourdoes = findViewById(R.id.ourdoes);
ourdoes.setLayoutManager(new LinearLayoutManager(this));
list = new ArrayList<MyDoes>();
// get data from firebase
reference = FirebaseDatabase.getInstance().getReference().child("DoesApp");
reference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// set code to retrive data and replace layout
for(DataSnapshot dataSnapshot1: dataSnapshot.getChildren())
{
MyDoes p = dataSnapshot1.getValue(MyDoes.class);
list.add(p);
}
doesAdapter = new DoesAdapter(MainActivity2.this, list);
ourdoes.setAdapter(doesAdapter);
doesAdapter.notifyDataSetChanged();
}
@Override
public void onCancelled(DatabaseError databaseError) {
// set code to show an error
Toast.makeText(getApplicationContext(), "No Data", Toast.LENGTH_SHORT).show();
}
});
}
NewTask Activity (если пользователь может добавить заголовок, описание напоминания, Я думаю, что таймер должен быть здесь)
public class NewTaskAct extends AppCompatActivity {
TextView titlepage, addtitle, adddesc, adddate;
EditText titledoes, descdoes, datedoes;
Button btnSaveTask, btnCancel;
DatabaseReference reference;
Integer doesNum = new Random().nextInt();
String keydoes = Integer.toString(doesNum);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_task);
titlepage = findViewById(R.id.titlepage);
addtitle = findViewById(R.id.addtitle);
adddesc = findViewById(R.id.adddesc);
adddate = findViewById(R.id.adddate);
titledoes = findViewById(R.id.titledoes);
descdoes = findViewById(R.id.descdoes);
datedoes = findViewById(R.id.datedoes);
btnSaveTask = findViewById(R.id.btnSaveTask);
btnCancel = findViewById(R.id.btnCancel);
btnSaveTask.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// insert data to database
reference = FirebaseDatabase.getInstance().getReference().child("DoesApp").
child("Does" + doesNum);
reference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
dataSnapshot.getRef().child("titledoes").setValue(titledoes.getText().toString());
dataSnapshot.getRef().child("descdoes").setValue(descdoes.getText().toString());
dataSnapshot.getRef().child("datedoes").setValue(datedoes.getText().toString());
dataSnapshot.getRef().child("keydoes").setValue(keydoes);
Intent a = new Intent(NewTaskAct.this,MainActivity2.class);
startActivity(a);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
});
}
}
Адаптер Я думаю, что таймер должен быть вызван здесь, но опять же, я не уверен
public class DoesAdapter extends RecyclerView.Adapter<DoesAdapter.MyViewHolder>{
Context context;
ArrayList<MyDoes> myDoes;
public DoesAdapter(Context c, ArrayList<MyDoes> p) {
context = c;
myDoes = p;
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
return new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.item_does,viewGroup, false));
}
@Override
public void onBindViewHolder(@NonNull final MyViewHolder myViewHolder, int i) {
myViewHolder.titledoes.setText(myDoes.get(i).getTitledoes());
myViewHolder.descdoes.setText(myDoes.get(i).getDescdoes());
myViewHolder.datedoes.setText(myDoes.get(i).getDatedoes());
final String getTitleDoes = myDoes.get(i).getTitledoes();
final String getDescDoes = myDoes.get(i).getDescdoes();
final String getDateDoes = myDoes.get(i).getDatedoes();
final String getKeyDoes = myDoes.get(i).getKeydoes();
myViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent aa = new Intent(context,EditTaskAct.class);
aa.putExtra("titledoes", getTitleDoes);
aa.putExtra("descdoes", getDescDoes);
aa.putExtra("datedoes", getDateDoes);
aa.putExtra("keydoes", getKeyDoes);
context.startActivity(aa);
}
});
}
@Override
public int getItemCount() {
return myDoes.size();
}
class MyViewHolder extends RecyclerView.ViewHolder {
TextView titledoes, descdoes, datedoes, keydoes;
public MyViewHolder(@NonNull View itemView) {
super(itemView);
titledoes = (TextView) itemView.findViewById(R.id.titledoes);
descdoes = (TextView) itemView.findViewById(R.id.descdoes);
datedoes = (TextView) itemView.findViewById(R.id.datedoes);
}
}
}
MyDoes (Где геттеры и сеттеры есть)
public class MyDoes {
String titledoes;
String datedoes;
String descdoes;
String keydoes;
public MyDoes() {
}
public MyDoes(String titledoes, String datedoes, String descdoes, String keydoes) {
this.titledoes = titledoes;
this.datedoes = datedoes;
this.descdoes = descdoes;
this.keydoes = keydoes;
}
public String getKeydoes() {
return keydoes;
}
public void setKeydoes(String keydoes) {
this.keydoes = keydoes;
}
public String getTitledoes() {
return titledoes;
}
public void setTitledoes(String titledoes) {
this.titledoes = titledoes;
}
public String getDatedoes() {
return datedoes;
}
public void setDatedoes(String datedoes) {
this.datedoes = datedoes;
}
public String getDescdoes() {
return descdoes;
}
public void setDescdoes(String descdoes) {
this.descdoes = descdoes;
}
}