2018-12-01 15:32:07 +01:00
|
|
|
/* Copyright 2017 Thomas Schneider
|
|
|
|
*
|
2019-05-18 11:10:30 +02:00
|
|
|
* This file is a part of Fedilab
|
2018-12-01 15:32:07 +01:00
|
|
|
*
|
|
|
|
* This program 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.
|
|
|
|
*
|
2019-05-18 11:10:30 +02:00
|
|
|
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
2018-12-01 15:32:07 +01:00
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
|
|
|
*
|
2019-05-18 11:10:30 +02:00
|
|
|
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
2018-12-01 15:32:07 +01:00
|
|
|
* see <http://www.gnu.org/licenses>. */
|
2019-05-18 11:10:30 +02:00
|
|
|
package app.fedilab.android.activities;
|
2018-12-01 15:32:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.database.sqlite.SQLiteDatabase;
|
|
|
|
import android.os.AsyncTask;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.ImageButton;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
2019-11-15 16:32:25 +01:00
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
2018-12-01 15:32:07 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2019-11-15 16:32:25 +01:00
|
|
|
import app.fedilab.android.R;
|
2019-05-18 11:10:30 +02:00
|
|
|
import app.fedilab.android.drawers.TagsEditAdapter;
|
|
|
|
import app.fedilab.android.helper.Helper;
|
|
|
|
import app.fedilab.android.sqlite.Sqlite;
|
|
|
|
import app.fedilab.android.sqlite.TagsCacheDAO;
|
2018-12-01 15:32:07 +01:00
|
|
|
import es.dmoral.toasty.Toasty;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Thomas on 01/12/2018.
|
|
|
|
* Tag cache activity class
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class TagCacheActivity extends BaseActivity {
|
|
|
|
|
|
|
|
private RecyclerView tag_list;
|
|
|
|
private List<String> tags;
|
|
|
|
private TagsEditAdapter tagsEditAdapter;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2019-05-18 11:10:30 +02:00
|
|
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
2018-12-01 15:32:07 +01:00
|
|
|
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
2019-11-07 19:51:53 +01:00
|
|
|
if (theme == Helper.THEME_LIGHT) {
|
2019-11-07 19:07:19 +01:00
|
|
|
setTheme(R.style.Dialog);
|
2019-11-07 19:51:53 +01:00
|
|
|
} else {
|
2019-11-07 19:07:19 +01:00
|
|
|
setTheme(R.style.DialogDark);
|
2018-12-01 15:32:07 +01:00
|
|
|
}
|
|
|
|
getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
|
|
|
|
|
|
tags = new ArrayList<>();
|
|
|
|
setContentView(R.layout.activity_tag_cache);
|
|
|
|
|
|
|
|
tag_list = findViewById(R.id.tag_list);
|
2020-04-09 18:57:12 +02:00
|
|
|
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
2018-12-01 15:32:07 +01:00
|
|
|
EditText tag_add = findViewById(R.id.tag_add);
|
|
|
|
ImageButton save_tag = findViewById(R.id.save_tag);
|
|
|
|
|
2020-06-17 18:20:35 +02:00
|
|
|
save_tag.setOnClickListener(v -> {
|
|
|
|
if (tag_add.getText() != null && tag_add.getText().toString().trim().replaceAll("#", "").length() > 0) {
|
|
|
|
String tagToInsert = tag_add.getText().toString().trim().replaceAll("#", "");
|
|
|
|
boolean isPresent = new TagsCacheDAO(TagCacheActivity.this, db).isPresent(tagToInsert);
|
|
|
|
if (isPresent)
|
|
|
|
Toasty.warning(TagCacheActivity.this, getString(R.string.tags_already_stored), Toast.LENGTH_LONG).show();
|
|
|
|
else {
|
|
|
|
new TagsCacheDAO(TagCacheActivity.this, db).insert(tagToInsert);
|
|
|
|
int position = tags.size();
|
|
|
|
tags.add(tagToInsert);
|
|
|
|
Toasty.success(TagCacheActivity.this, getString(R.string.tags_stored), Toast.LENGTH_LONG).show();
|
|
|
|
tag_add.setText("");
|
|
|
|
tagsEditAdapter.notifyItemInserted(position);
|
2018-12-01 15:32:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
setTitle(R.string.manage_tags);
|
2020-06-17 18:20:35 +02:00
|
|
|
AsyncTask.execute(() -> {
|
|
|
|
|
|
|
|
List<String> tagsTemp = new TagsCacheDAO(TagCacheActivity.this, db).getAll();
|
|
|
|
if (tagsTemp != null)
|
|
|
|
tags = tagsTemp;
|
|
|
|
if (tags != null) {
|
|
|
|
tagsEditAdapter = new TagsEditAdapter(tags);
|
|
|
|
tag_list.setAdapter(tagsEditAdapter);
|
|
|
|
LinearLayoutManager mLayoutManager = new LinearLayoutManager(TagCacheActivity.this);
|
|
|
|
tag_list.setLayoutManager(mLayoutManager);
|
2018-12-01 15:32:07 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|