Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Individual extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_individual);
- //referência ao arquivo que armazena os valores
- final SharedPreferences settings = getApplicationContext().getSharedPreferences("tarefafile", 0);
- final SharedPreferences.Editor editor = settings.edit();
- //pega valores enviados pela página Novo Texto, salva em uma string e limpa o arquivo
- final String tarefaTit = settings.getString("tarefatit", null);
- editor.remove("tarefatit");
- //recebe valores préviamente salvos, caso existam
- String tarefa1tit = settings.getString("tarefa1tit", null);
- String tarefa2tit = settings.getString("tarefa2tit", null);
- String tarefa3tit = settings.getString("tarefa3tit", null);
- String tarefa4tit = settings.getString("tarefa4tit", null);
- String tarefa5tit = settings.getString("tarefa5tit", null);
- String tarefa6tit = settings.getString("tarefa6tit", null);
- String tarefa7tit = settings.getString("tarefa7tit", null);
- String tarefa8tit = settings.getString("tarefa8tit", null);
- String tarefa9tit = settings.getString("tarefa9tit", null);
- String tarefa10tit = settings.getString("tarefa10tit", null);
- String tarefa11tit = settings.getString("tarefa11tit", null);
- String tarefa12tit = settings.getString("tarefa12tit", null);
- String tarefa13tit = settings.getString("tarefa13tit", null);
- //declara textviews
- TextView tarefa1view = findViewById(R.id.textView9);
- TextView tarefa2view = findViewById(R.id.textView10);
- TextView tarefa3view = findViewById(R.id.textView11);
- TextView tarefa4view = findViewById(R.id.textView12);
- TextView tarefa5view = findViewById(R.id.textView17);
- TextView tarefa6view = findViewById(R.id.textView18);
- TextView tarefa7view = findViewById(R.id.textView19);
- TextView tarefa8view = findViewById(R.id.textView20);
- TextView tarefa9view = findViewById(R.id.textView21);
- TextView tarefa10view = findViewById(R.id.textView22);
- TextView tarefa11view = findViewById(R.id.textView23);
- TextView tarefa12view = findViewById(R.id.textView24);
- TextView tarefa13view = findViewById(R.id.textView25);
- //confere se há valores enviados pela página Novo Texto, se houver, confere se há tarefa em branco para colocar o valor
- if(tarefaTit!=null){
- if(tarefa1tit==null){
- tarefa1view.append("*");
- tarefa1view.append(tarefaTit);
- editor.putString("tarefa1tit", tarefaTit);}
- else if(tarefa2tit==null){
- tarefa2view.append("*");
- tarefa2view.append(tarefaTit);
- editor.putString("tarefa2tit", tarefaTit);}
- else if(tarefa3tit==null){
- tarefa3view.append("*");
- tarefa3view.append(tarefaTit);
- editor.putString("tarefa3tit", tarefaTit);}
- else if(tarefa4tit==null){
- tarefa4view.append("*");
- tarefa4view.append(tarefaTit);
- editor.putString("tarefa4tit", tarefaTit);}
- else if(tarefa5tit==null){
- tarefa5view.append("*");
- tarefa5view.append(tarefaTit);
- editor.putString("tarefa5tit", tarefaTit);}
- else if(tarefa6tit==null){
- tarefa6view.append("*");
- tarefa6view.append(tarefaTit);
- editor.putString("tarefa6tit", tarefaTit);}
- else if(tarefa7tit==null){
- tarefa7view.append("*");
- tarefa7view.append(tarefaTit);
- editor.putString("tarefa7tit", tarefaTit);}
- else if(tarefa8tit==null){
- tarefa8view.append("*");
- tarefa8view.append(tarefaTit);
- editor.putString("tarefa8tit", tarefaTit);}
- else if(tarefa9tit==null){
- tarefa9view.append("*");
- tarefa9view.append(tarefaTit);
- editor.putString("tarefa9tit", tarefaTit);}
- else if(tarefa10tit==null){
- tarefa10view.append("*");
- tarefa10view.append(tarefaTit);
- editor.putString("tarefa10tit", tarefaTit);}
- else if(tarefa11tit==null){
- tarefa11view.append("*");
- tarefa11view.append(tarefaTit);
- editor.putString("tarefa11tit", tarefaTit);}
- else if(tarefa12tit==null){
- tarefa12view.append("*");
- tarefa12view.append(tarefaTit);
- editor.putString("tarefa12tit", tarefaTit);}
- else if(tarefa13tit==null){
- tarefa13view.append("*");
- tarefa13view.append(tarefaTit);
- editor.putString("tarefa13tit", tarefaTit);}
- }
- //coloca as strings na tela em ordem
- if(tarefa13tit!=null){
- if(tarefa12tit==null){
- tarefa12tit = tarefa13tit;}
- else{
- tarefa13view.clearComposingText();
- tarefa13view.append("*");
- tarefa13view.append(tarefa13tit);}}
- if(tarefa13tit==null){
- tarefa13view.clearComposingText();}
- if(tarefa12tit!=null){
- if(tarefa11tit==null){
- tarefa11tit = tarefa13tit;}
- else{
- tarefa12view.clearComposingText();
- tarefa12view.append("*");
- tarefa12view.append(tarefa12tit);}}
- if(tarefa12tit==null){
- tarefa12view.clearComposingText();}
- if(tarefa11tit!=null){
- if(tarefa10tit==null){
- tarefa10tit=tarefa11tit;}
- else{
- tarefa11view.clearComposingText();
- tarefa11view.append("*");
- tarefa11view.append(tarefa11tit);}}
- if(tarefa11tit==null){
- tarefa11view.clearComposingText();}
- if(tarefa10tit!=null){
- if(tarefa9tit==null){
- tarefa9tit=tarefa10tit;}
- else{
- tarefa10view.clearComposingText();
- tarefa10view.append("*");
- tarefa10view.append(tarefa10tit);}}
- if(tarefa10tit==null){
- tarefa10view.clearComposingText();}
- if(tarefa9tit!=null){
- if(tarefa8tit==null){
- tarefa8tit=tarefa9tit;}
- else{
- tarefa9view.clearComposingText();
- tarefa9view.append("*");
- tarefa9view.append(tarefa9tit);}}
- if(tarefa9tit==null){
- tarefa9view.clearComposingText();}
- if(tarefa8tit!=null){
- if(tarefa7tit==null){
- tarefa7tit=tarefa8tit;}
- else{
- tarefa8view.clearComposingText();
- tarefa8view.append("*");
- tarefa8view.append(tarefa8tit);}}
- if(tarefa8tit==null){
- tarefa8view.clearComposingText();}
- if(tarefa7tit!=null){
- if(tarefa6tit==null){
- tarefa6tit=tarefa7tit;}
- else{
- tarefa7view.clearComposingText();
- tarefa7view.append("*");
- tarefa7view.append(tarefa7tit);}}
- if(tarefa7tit==null){
- tarefa7view.clearComposingText();}
- if(tarefa6tit!=null){
- if(tarefa5tit==null){
- tarefa5tit=tarefa6tit;}
- else{
- tarefa6view.clearComposingText();
- tarefa6view.append("*");
- tarefa6view.append(tarefa6tit);}}
- if(tarefa6tit==null){
- tarefa6view.clearComposingText();}
- if(tarefa5tit!=null){
- if(tarefa4tit==null){
- tarefa4tit=tarefa5tit;}
- else{
- tarefa5view.clearComposingText();
- tarefa5view.append("*");
- tarefa5view.append(tarefa5tit);}}
- if(tarefa5tit==null){
- tarefa5view.clearComposingText();}
- if(tarefa4tit!=null){
- if(tarefa3tit==null){
- tarefa3tit=tarefa4tit;}
- else{
- tarefa4view.clearComposingText();
- tarefa4view.append("*");
- tarefa4view.append(tarefa4tit);}}
- if(tarefa4tit==null){
- tarefa4view.clearComposingText();}
- if(tarefa3tit!=null){
- if(tarefa2tit==null){
- tarefa2tit=tarefa3tit;}
- else{
- tarefa3view.clearComposingText();
- tarefa3view.append("*");
- tarefa3view.append(tarefa3tit);}}
- if(tarefa3tit==null){
- tarefa3view.clearComposingText();}
- if(tarefa2tit!=null){
- if(tarefa1tit==null){
- tarefa1tit=tarefa2tit;}
- else{
- tarefa2view.clearComposingText();
- tarefa2view.append("*");
- tarefa2view.append(tarefa2tit);}}
- if(tarefa2tit==null){
- tarefa2view.clearComposingText();}
- if(tarefa1tit!=null){
- tarefa1view.clearComposingText();
- tarefa1view.append("*");
- tarefa1view.append(tarefa1tit);}
- if(tarefa1tit==null){
- tarefa1view.clearComposingText();}
- //click longo para opções
- tarefa1view.setOnLongClickListener(new View.OnLongClickListener() {
- @Override
- public boolean onLongClick(View v) {
- //ao segurar o texview:
- //aparecem checkbox em cada texview >em q tiver tarefa<
- //aparece navigation view com opções e delete
- return false;
- }
- });
- final String canDelete = tarefa1tit;
- final String canAdd = tarefa13tit;
- //botão deletar
- Button deleteTask1Btn = findViewById(R.id.deleteTask1Btn);
- deleteTask1Btn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- editor.remove("tarefa1tit");
- editor.remove("tarefa2tit");
- editor.remove("tarefa3tit");
- editor.remove("tarefa4tit");
- editor.remove("tarefa5tit");
- editor.remove("tarefa6tit");
- editor.remove("tarefa7tit");
- editor.remove("tarefa8tit");
- editor.remove("tarefa9tit");
- editor.remove("tarefa10tit");
- editor.remove("tarefa11tit");
- editor.remove("tarefa12tit");
- editor.remove("tarefa13tit");
- editor.commit();
- recreate();
- if(canDelete!=null){
- Toast.makeText(Individual.this, "Tarefas removidas", Toast.LENGTH_SHORT).show();}
- else{
- Toast.makeText(Individual.this, "Não há tarefas", Toast.LENGTH_SHORT).show();}
- }
- });
- //toolbar
- Toolbar toolbar = findViewById(R.id.toolbar);
- setSupportActionBar(toolbar);
- //botao adicionar tarefa
- FloatingActionButton newTask = findViewById(R.id.newTaskFab);
- newTask.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if(canAdd!=null){
- Toast.makeText(Individual.this, "Não há mais espaço", Toast.LENGTH_SHORT).show();}
- else{
- Intent intent = new Intent(Individual.this, NovoTexto.class);
- startActivity(intent);
- Toast.makeText(Individual.this, "Nova tarefa", Toast.LENGTH_SHORT).show();}
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement