Skip to content
Commits on Source (25)
......@@ -97,11 +97,16 @@ release:
- wget --quiet --output-document=/tmp/nvm-install.sh https://raw.githubusercontent.com/creationix/nvm/v0.33.6/install.sh
- bash /tmp/nvm-install.sh
- export NVM_DIR="$HOME/.nvm" &&. "$NVM_DIR/nvm.sh" && nvm install 8
- npm install -g semantic-release @semantic-release/commit-analyzer @semantic-release/release-notes-generator @semantic-release/changelog @semantic-release/exec @semantic-release/git @semantic-release/gitlab
- eval $(ssh-agent -s)
- ssh-add <(echo "$GIT_SSH_KEY")
- mkdir -p ~/.ssh && ssh-keyscan $GITLAB_URL >> ~/.ssh/known_hosts
- git config --global user.email $GIT_AUTHOR_EMAIL
- git config --global user.name $GIT_AUTHOR_NAME
cache: {}
script:
- npm install -g semantic-release @semantic-release/commit-analyzer @semantic-release/release-notes-generator @semantic-release/changelog @semantic-release/exec @semantic-release/git @semantic-release/gitlab
- semantic-release
- git fetch
- git checkout develop
- git rebase origin/master
- git push https://${GIT_CREDENTIALS}@${GITLAB_URL}/${CI_PROJECT_PATH}.git develop
- git push git@${GITLAB_URL}:${CI_PROJECT_PATH}.git develop
......@@ -2,11 +2,11 @@ plugins:
- "@semantic-release/commit-analyzer"
- "@semantic-release/release-notes-generator"
- "@semantic-release/changelog"
- "@semantic-release/exec":
- prepareCmd: 'VERSIONCODE=`grep "versionCode .*" app/build.gradle | sed "s/versionCode //"` && sed -i "s/versionCode .*$/versionCode $(($VERSIONCODE + 1))/; s/versionName .*$/versionName \"${nextRelease.version}"/" app/build.gradle'
- "@semantic-release/git":
- assets:
- CHANGELOG.md
- app/build.gradle
- message: "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
- - "@semantic-release/exec"
- prepareCmd: './scripts/prepare.sh ${nextRelease.version}'
- - "@semantic-release/git"
- assets:
- CHANGELOG.md
- app/build.gradle
message: "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
- "@semantic-release/gitlab"
## [1.1.2](https://framagit.org/dystopia-project/simple-email/compare/v1.1.1...v1.1.2) (2018-11-20)
### Bug Fixes
* cancel single notification per account ([656e51e](https://framagit.org/dystopia-project/simple-email/commit/656e51e))
* focus body on reply message ([4b6e230](https://framagit.org/dystopia-project/simple-email/commit/4b6e230))
* message when no have identities ([4595289](https://framagit.org/dystopia-project/simple-email/commit/4595289))
* wrong riseup smtp port ([ecd870c](https://framagit.org/dystopia-project/simple-email/commit/ecd870c))
# Change Log
All notable changes to this project will be documented in this file.
......
......@@ -7,8 +7,8 @@ android {
applicationId "org.dystopia.email"
minSdkVersion 23
targetSdkVersion 28
versionCode 111
versionName "1.1.1"
versionCode 112
versionName "1.1.2"
archivesBaseName = "SimpleEmail-v$versionName"
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
......@@ -21,6 +21,7 @@ android {
buildTypes {
debug {
applicationIdSuffix ".debug"
debuggable = true
minifyEnabled !rootProject.ext.ci
useProguard = true
......
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_label" translatable="false">Smail Debug</string>
</resources>
......@@ -30,74 +30,73 @@ import java.util.ArrayList;
import java.util.List;
abstract class ActivityBase extends AppCompatActivity
implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.i(
Helper.TAG,
"Create " + this.getClass().getName() + " version=" + BuildConfig.VERSION_NAME);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
String theme = prefs.getString("theme", "light");
setTheme("light".equals(theme) ? R.style.AppThemeLight : R.style.AppThemeDark);
prefs.registerOnSharedPreferenceChangeListener(this);
super.onCreate(savedInstanceState);
implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.i(
Helper.TAG, "Create " + this.getClass().getName() + " version=" + BuildConfig.VERSION_NAME);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
String theme = prefs.getString("theme", "light");
setTheme("light".equals(theme) ? R.style.AppThemeLight : R.style.AppThemeDark);
prefs.registerOnSharedPreferenceChangeListener(this);
super.onCreate(savedInstanceState);
}
@Override
protected void onResume() {
Log.i(Helper.TAG, "Resume " + this.getClass().getName());
super.onResume();
}
@Override
protected void onPause() {
Log.i(Helper.TAG, "Pause " + this.getClass().getName());
super.onPause();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
Log.i(Helper.TAG, "Config " + this.getClass().getName());
super.onConfigurationChanged(newConfig);
}
@Override
protected void onDestroy() {
Log.i(Helper.TAG, "Destroy " + this.getClass().getName());
PreferenceManager.getDefaultSharedPreferences(this)
.unregisterOnSharedPreferenceChangeListener(this);
super.onDestroy();
}
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
Log.i(Helper.TAG, "Preference " + key + "=" + prefs.getAll().get(key));
if ("theme".equals(key)) {
finish();
startActivity(getIntent());
} else if (!this.getClass().equals(ActivitySetup.class)
&& ("compact".equals(key) || "debug".equals(key))) {
finish();
}
}
@Override
protected void onResume() {
Log.i(Helper.TAG, "Resume " + this.getClass().getName());
super.onResume();
}
@Override
protected void onPause() {
Log.i(Helper.TAG, "Pause " + this.getClass().getName());
super.onPause();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
Log.i(Helper.TAG, "Config " + this.getClass().getName());
super.onConfigurationChanged(newConfig);
}
@Override
protected void onDestroy() {
Log.i(Helper.TAG, "Destroy " + this.getClass().getName());
PreferenceManager.getDefaultSharedPreferences(this)
.unregisterOnSharedPreferenceChangeListener(this);
super.onDestroy();
}
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
Log.i(Helper.TAG, "Preference " + key + "=" + prefs.getAll().get(key));
if ("theme".equals(key)) {
finish();
startActivity(getIntent());
} else if (!this.getClass().equals(ActivitySetup.class)
&& ("compact".equals(key) || "debug".equals(key))) {
finish();
}
}
private List<IBackPressedListener> backPressedListeners = new ArrayList<>();
private List<IBackPressedListener> backPressedListeners = new ArrayList<>();
public void addBackPressedListener(IBackPressedListener listener) {
backPressedListeners.add(listener);
}
public void addBackPressedListener(IBackPressedListener listener) {
backPressedListeners.add(listener);
@Override
public void onBackPressed() {
for (IBackPressedListener listener : backPressedListeners) {
if (listener.onBackPressed()) {
return;
}
}
super.onBackPressed();
}
@Override
public void onBackPressed() {
for (IBackPressedListener listener : backPressedListeners) {
if (listener.onBackPressed()) {
return;
}
}
super.onBackPressed();
}
public interface IBackPressedListener {
boolean onBackPressed();
}
public interface IBackPressedListener {
boolean onBackPressed();
}
}
......@@ -30,126 +30,123 @@ import androidx.lifecycle.Lifecycle;
import java.util.ArrayList;
public class ActivityCompose extends ActivityBase
implements FragmentManager.OnBackStackChangedListener {
static final int REQUEST_CONTACT_TO = 1;
static final int REQUEST_CONTACT_CC = 2;
static final int REQUEST_CONTACT_BCC = 3;
static final int REQUEST_IMAGE = 4;
static final int REQUEST_ATTACHMENT = 5;
static final int REQUEST_ENCRYPT = 6;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_compose);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportFragmentManager().addOnBackStackChangedListener(this);
if (getSupportFragmentManager().getFragments().size() == 0) {
Bundle args;
Intent intent = getIntent();
String action = intent.getAction();
if (Intent.ACTION_VIEW.equals(action)
|| Intent.ACTION_SENDTO.equals(action)
|| Intent.ACTION_SEND.equals(action)
|| Intent.ACTION_SEND_MULTIPLE.equals(action)) {
args = new Bundle();
args.putString("action", "new");
args.putLong("account", -1);
Uri uri = intent.getData();
if (uri != null && "mailto".equals(uri.getScheme())) {
String to = uri.getSchemeSpecificPart();
if (to != null) {
args.putString("to", to);
}
}
if (intent.hasExtra(Intent.EXTRA_EMAIL)) {
String[] to = intent.getStringArrayExtra(Intent.EXTRA_EMAIL);
if (to != null) {
args.putString("to", TextUtils.join(", ", to));
}
}
if (intent.hasExtra(Intent.EXTRA_CC)) {
String[] cc = intent.getStringArrayExtra(Intent.EXTRA_CC);
if (cc != null) {
args.putString("cc", TextUtils.join(", ", cc));
}
}
if (intent.hasExtra(Intent.EXTRA_BCC)) {
String[] bcc = intent.getStringArrayExtra(Intent.EXTRA_BCC);
if (bcc != null) {
args.putString("bcc", TextUtils.join(", ", bcc));
}
}
if (intent.hasExtra(Intent.EXTRA_SUBJECT)) {
String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
if (subject != null) {
args.putString("subject", subject);
}
}
if (intent.hasExtra(Intent.EXTRA_TEXT)) {
String body =
intent.getStringExtra(Intent.EXTRA_TEXT); // Intent.EXTRA_HTML_TEXT
if (body != null) {
args.putString("body", body);
}
}
if (intent.hasExtra(Intent.EXTRA_STREAM)) {
if (Intent.ACTION_SEND_MULTIPLE.equals(action)) {
ArrayList<Uri> uris =
intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
if (uris != null) {
args.putParcelableArrayList("attachments", uris);
}
} else {
Uri stream = intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (stream != null) {
ArrayList<Uri> uris = new ArrayList<>();
uris.add((Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM));
args.putParcelableArrayList("attachments", uris);
}
}
}
} else {
args = intent.getExtras();
}
implements FragmentManager.OnBackStackChangedListener {
static final int REQUEST_CONTACT_TO = 1;
static final int REQUEST_CONTACT_CC = 2;
static final int REQUEST_CONTACT_BCC = 3;
static final int REQUEST_IMAGE = 4;
static final int REQUEST_ATTACHMENT = 5;
static final int REQUEST_ENCRYPT = 6;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_compose);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportFragmentManager().addOnBackStackChangedListener(this);
if (getSupportFragmentManager().getFragments().size() == 0) {
Bundle args;
Intent intent = getIntent();
String action = intent.getAction();
if (Intent.ACTION_VIEW.equals(action)
|| Intent.ACTION_SENDTO.equals(action)
|| Intent.ACTION_SEND.equals(action)
|| Intent.ACTION_SEND_MULTIPLE.equals(action)) {
args = new Bundle();
args.putString("action", "new");
args.putLong("account", -1);
Uri uri = intent.getData();
if (uri != null && "mailto".equals(uri.getScheme())) {
String to = uri.getSchemeSpecificPart();
if (to != null) {
args.putString("to", to);
}
}
FragmentCompose fragment = new FragmentCompose();
fragment.setArguments(args);
if (intent.hasExtra(Intent.EXTRA_EMAIL)) {
String[] to = intent.getStringArrayExtra(Intent.EXTRA_EMAIL);
if (to != null) {
args.putString("to", TextUtils.join(", ", to));
}
}
FragmentTransaction fragmentTransaction =
getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("compose");
fragmentTransaction.commit();
if (intent.hasExtra(Intent.EXTRA_CC)) {
String[] cc = intent.getStringArrayExtra(Intent.EXTRA_CC);
if (cc != null) {
args.putString("cc", TextUtils.join(", ", cc));
}
}
if (intent.hasExtra(Intent.EXTRA_BCC)) {
String[] bcc = intent.getStringArrayExtra(Intent.EXTRA_BCC);
if (bcc != null) {
args.putString("bcc", TextUtils.join(", ", bcc));
}
}
if (intent.hasExtra(Intent.EXTRA_SUBJECT)) {
String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
if (subject != null) {
args.putString("subject", subject);
}
}
}
@Override
public void onBackStackChanged() {
if (getSupportFragmentManager().getBackStackEntryCount() == 0) {
finish();
if (intent.hasExtra(Intent.EXTRA_TEXT)) {
String body = intent.getStringExtra(Intent.EXTRA_TEXT); // Intent.EXTRA_HTML_TEXT
if (body != null) {
args.putString("body", body);
}
}
if (intent.hasExtra(Intent.EXTRA_STREAM)) {
if (Intent.ACTION_SEND_MULTIPLE.equals(action)) {
ArrayList<Uri> uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
if (uris != null) {
args.putParcelableArrayList("attachments", uris);
}
} else {
Uri stream = intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (stream != null) {
ArrayList<Uri> uris = new ArrayList<>();
uris.add((Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM));
args.putParcelableArrayList("attachments", uris);
}
}
}
} else {
args = intent.getExtras();
}
FragmentCompose fragment = new FragmentCompose();
fragment.setArguments(args);
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("compose");
fragmentTransaction.commit();
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) {
getSupportFragmentManager().popBackStack();
}
return true;
default:
return false;
@Override
public void onBackStackChanged() {
if (getSupportFragmentManager().getBackStackEntryCount() == 0) {
finish();
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) {
getSupportFragmentManager().popBackStack();
}
return true;
default:
return false;
}
}
}
......@@ -28,38 +28,36 @@ import androidx.lifecycle.Observer;
import java.util.List;
public class ActivityMain extends AppCompatActivity
implements FragmentManager.OnBackStackChangedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
getSupportFragmentManager().addOnBackStackChangedListener(this);
super.onCreate(savedInstanceState);
DB.getInstance(this)
.account()
.liveAccounts(true)
.observe(
this,
new Observer<List<EntityAccount>>() {
@Override
public void onChanged(@Nullable List<EntityAccount> accounts) {
if (accounts == null || accounts.size() == 0) {
startActivity(
new Intent(ActivityMain.this, ActivitySetup.class));
} else {
startActivity(
new Intent(ActivityMain.this, ActivityView.class));
ServiceSynchronize.init(ActivityMain.this);
}
finish();
}
});
}
@Override
public void onBackStackChanged() {
int count = getSupportFragmentManager().getBackStackEntryCount();
if (count == 0) {
finish();
}
implements FragmentManager.OnBackStackChangedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
getSupportFragmentManager().addOnBackStackChangedListener(this);
super.onCreate(savedInstanceState);
DB.getInstance(this)
.account()
.liveAccounts(true)
.observe(
this,
new Observer<List<EntityAccount>>() {
@Override
public void onChanged(@Nullable List<EntityAccount> accounts) {
if (accounts == null || accounts.size() == 0) {
startActivity(new Intent(ActivityMain.this, ActivitySetup.class));
} else {
startActivity(new Intent(ActivityMain.this, ActivityView.class));
ServiceSynchronize.init(ActivityMain.this);
}
finish();
}
});
}
@Override
public void onBackStackChanged() {
int count = getSupportFragmentManager().getBackStackEntryCount();
if (count == 0) {
finish();
}
}
}
......@@ -33,111 +33,104 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import java.util.List;
public class ActivitySetup extends ActivityBase
implements FragmentManager.OnBackStackChangedListener {
private boolean hasAccount;
implements FragmentManager.OnBackStackChangedListener {
private boolean hasAccount;
static final int REQUEST_PERMISSION = 1;
static final int REQUEST_CHOOSE_ACCOUNT = 2;
static final int REQUEST_PERMISSION = 1;
static final int REQUEST_CHOOSE_ACCOUNT = 2;
static final int REQUEST_EXPORT = 3;
static final int REQUEST_IMPORT = 4;
static final int REQUEST_EXPORT = 3;
static final int REQUEST_IMPORT = 4;
static final String ACTION_EDIT_ACCOUNT = BuildConfig.APPLICATION_ID + ".EDIT_ACCOUNT";
static final String ACTION_EDIT_IDENTITY = BuildConfig.APPLICATION_ID + ".EDIT_IDENTITY";
static final String ACTION_EDIT_ACCOUNT = BuildConfig.APPLICATION_ID + ".EDIT_ACCOUNT";
static final String ACTION_EDIT_IDENTITY = BuildConfig.APPLICATION_ID + ".EDIT_IDENTITY";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setup);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setup);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportFragmentManager().addOnBackStackChangedListener(this);
getSupportFragmentManager().addOnBackStackChangedListener(this);
if (getSupportFragmentManager().getFragments().size() == 0) {
FragmentTransaction fragmentTransaction =
getSupportFragmentManager().beginTransaction();
fragmentTransaction
.replace(R.id.content_frame, new FragmentSetup())
.addToBackStack("setup");
fragmentTransaction.commit();
}
DB.getInstance(this)
.account()
.liveAccounts(true)
.observe(
this,
new Observer<List<EntityAccount>>() {
@Override
public void onChanged(List<EntityAccount> accounts) {
hasAccount = (accounts != null && accounts.size() > 0);
}
});
}
@Override
protected void onResume() {
super.onResume();
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
IntentFilter iff = new IntentFilter();
iff.addAction(ACTION_EDIT_ACCOUNT);
iff.addAction(ACTION_EDIT_IDENTITY);
lbm.registerReceiver(receiver, iff);
}
@Override
protected void onPause() {
super.onPause();
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
lbm.unregisterReceiver(receiver);
if (getSupportFragmentManager().getFragments().size() == 0) {
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_frame, new FragmentSetup()).addToBackStack("setup");
fragmentTransaction.commit();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) {
getSupportFragmentManager().popBackStack();
}
return true;
DB.getInstance(this)
.account()
.liveAccounts(true)
.observe(
this,
new Observer<List<EntityAccount>>() {
@Override
public void onChanged(List<EntityAccount> accounts) {
hasAccount = (accounts != null && accounts.size() > 0);
}
});
}
@Override
protected void onResume() {
super.onResume();
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
IntentFilter iff = new IntentFilter();
iff.addAction(ACTION_EDIT_ACCOUNT);
iff.addAction(ACTION_EDIT_IDENTITY);
lbm.registerReceiver(receiver, iff);
}
@Override
protected void onPause() {
super.onPause();
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
lbm.unregisterReceiver(receiver);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) {
getSupportFragmentManager().popBackStack();
}
return super.onOptionsItemSelected(item);
return true;
}
@Override
public void onBackStackChanged() {
if (getSupportFragmentManager().getBackStackEntryCount() == 0) {
if (hasAccount) {
startActivity(new Intent(this, ActivityView.class));
}
finish();
}
return super.onOptionsItemSelected(item);
}
@Override
public void onBackStackChanged() {
if (getSupportFragmentManager().getBackStackEntryCount() == 0) {
if (hasAccount) {
startActivity(new Intent(this, ActivityView.class));
}
finish();
}
BroadcastReceiver receiver =
new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (ACTION_EDIT_ACCOUNT.equals(intent.getAction())) {
FragmentAccount fragment = new FragmentAccount();
fragment.setArguments(intent.getExtras());
FragmentTransaction fragmentTransaction =
getSupportFragmentManager().beginTransaction();
fragmentTransaction
.replace(R.id.content_frame, fragment)
.addToBackStack("account");
fragmentTransaction.commit();
} else if (ACTION_EDIT_IDENTITY.equals(intent.getAction())) {
FragmentIdentity fragment = new FragmentIdentity();
fragment.setArguments(intent.getExtras());
FragmentTransaction fragmentTransaction =
getSupportFragmentManager().beginTransaction();
fragmentTransaction
.replace(R.id.content_frame, fragment)
.addToBackStack("identity");
fragmentTransaction.commit();
}
}
};
}
BroadcastReceiver receiver =
new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (ACTION_EDIT_ACCOUNT.equals(intent.getAction())) {
FragmentAccount fragment = new FragmentAccount();
fragment.setArguments(intent.getExtras());
FragmentTransaction fragmentTransaction =
getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("account");
fragmentTransaction.commit();
} else if (ACTION_EDIT_IDENTITY.equals(intent.getAction())) {
FragmentIdentity fragment = new FragmentIdentity();
fragment.setArguments(intent.getExtras());
FragmentTransaction fragmentTransaction =
getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("identity");
fragmentTransaction.commit();
}
}
};
}
......@@ -41,194 +41,191 @@ import java.util.List;
import java.util.Locale;
public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHolder> {
private Context context;
private List<EntityAccount> all = new ArrayList<>();
private List<EntityAccount> filtered = new ArrayList<>();
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
View itemView;
View vwColor;
ImageView ivPrimary;
TextView tvName;
ImageView ivSync;
TextView tvUser;
TextView tvHost;
ImageView ivState;
TextView tvError;
ViewHolder(View itemView) {
super(itemView);
this.itemView = itemView;
vwColor = itemView.findViewById(R.id.vwColor);
ivPrimary = itemView.findViewById(R.id.ivPrimary);
tvName = itemView.findViewById(R.id.tvName);
ivSync = itemView.findViewById(R.id.ivSync);
tvUser = itemView.findViewById(R.id.tvUser);
tvHost = itemView.findViewById(R.id.tvHost);
ivState = itemView.findViewById(R.id.ivState);
tvError = itemView.findViewById(R.id.tvError);
}
private void wire() {
itemView.setOnClickListener(this);
}
private void unwire() {
itemView.setOnClickListener(null);
}
private void bindTo(EntityAccount account) {
vwColor.setBackgroundColor(account.color == null ? Color.TRANSPARENT : account.color);
ivPrimary.setVisibility(account.primary ? View.VISIBLE : View.INVISIBLE);
tvName.setText(account.name);
ivSync.setImageResource(
account.synchronize
? R.drawable.baseline_sync_24
: R.drawable.baseline_sync_disabled_24);
tvUser.setText(account.user);
tvHost.setText(String.format(Locale.US, "%s:%d", account.host, account.port));
if ("connected".equals(account.state)) {
ivState.setImageResource(R.drawable.baseline_cloud_24);
} else if ("connecting".equals(account.state)) {
ivState.setImageResource(R.drawable.baseline_cloud_queue_24);
} else if ("closing".equals(account.state)) {
ivState.setImageResource(R.drawable.baseline_close_24);
} else {
ivState.setImageResource(R.drawable.baseline_cloud_off_24);
}
ivState.setVisibility(account.synchronize ? View.VISIBLE : View.INVISIBLE);
tvError.setText(account.error);
tvError.setVisibility(account.error == null ? View.GONE : View.VISIBLE);
}
@Override
public void onClick(View view) {
int pos = getAdapterPosition();
if (pos == RecyclerView.NO_POSITION) {
return;
}
EntityAccount account = filtered.get(pos);
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(
new Intent(ActivitySetup.ACTION_EDIT_ACCOUNT).putExtra("id", account.id));
}
private Context context;
private List<EntityAccount> all = new ArrayList<>();
private List<EntityAccount> filtered = new ArrayList<>();
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
View itemView;
View vwColor;
ImageView ivPrimary;
TextView tvName;
ImageView ivSync;
TextView tvUser;
TextView tvHost;
ImageView ivState;
TextView tvError;
ViewHolder(View itemView) {
super(itemView);
this.itemView = itemView;
vwColor = itemView.findViewById(R.id.vwColor);
ivPrimary = itemView.findViewById(R.id.ivPrimary);
tvName = itemView.findViewById(R.id.tvName);
ivSync = itemView.findViewById(R.id.ivSync);
tvUser = itemView.findViewById(R.id.tvUser);
tvHost = itemView.findViewById(R.id.tvHost);
ivState = itemView.findViewById(R.id.ivState);
tvError = itemView.findViewById(R.id.tvError);
}
AdapterAccount(Context context) {
this.context = context;
setHasStableIds(true);
private void wire() {
itemView.setOnClickListener(this);
}
public void set(@NonNull List<EntityAccount> accounts) {
Log.i(Helper.TAG, "Set accounts=" + accounts.size());
final Collator collator = Collator.getInstance(Locale.getDefault());
collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc
Collections.sort(
accounts,
new Comparator<EntityAccount>() {
@Override
public int compare(EntityAccount a1, EntityAccount a2) {
return collator.compare(a1.host, a2.host);
}
});
all = accounts;
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 void unwire() {
itemView.setOnClickListener(null);
}
private class MessageDiffCallback extends DiffUtil.Callback {
private List<EntityAccount> prev;
private List<EntityAccount> next;
MessageDiffCallback(List<EntityAccount> prev, List<EntityAccount> 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) {
EntityAccount f1 = prev.get(oldItemPosition);
EntityAccount f2 = next.get(newItemPosition);
return f1.id.equals(f2.id);
}
@Override
public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
EntityAccount f1 = prev.get(oldItemPosition);
EntityAccount f2 = next.get(newItemPosition);
return f1.equals(f2);
}
private void bindTo(EntityAccount account) {
vwColor.setBackgroundColor(account.color == null ? Color.TRANSPARENT : account.color);
ivPrimary.setVisibility(account.primary ? View.VISIBLE : View.INVISIBLE);
tvName.setText(account.name);
ivSync.setImageResource(
account.synchronize ? R.drawable.baseline_sync_24 : R.drawable.baseline_sync_disabled_24);
tvUser.setText(account.user);
tvHost.setText(String.format(Locale.US, "%s:%d", account.host, account.port));
if ("connected".equals(account.state)) {
ivState.setImageResource(R.drawable.baseline_cloud_24);
} else if ("connecting".equals(account.state)) {
ivState.setImageResource(R.drawable.baseline_cloud_queue_24);
} else if ("closing".equals(account.state)) {
ivState.setImageResource(R.drawable.baseline_close_24);
} else {
ivState.setImageResource(R.drawable.baseline_cloud_off_24);
}
ivState.setVisibility(account.synchronize ? View.VISIBLE : View.INVISIBLE);
tvError.setText(account.error);
tvError.setVisibility(account.error == null ? View.GONE : View.VISIBLE);
}
@Override
public long getItemId(int position) {
return filtered.get(position).id;
public void onClick(View view) {
int pos = getAdapterPosition();
if (pos == RecyclerView.NO_POSITION) {
return;
}
EntityAccount account = filtered.get(pos);
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(new Intent(ActivitySetup.ACTION_EDIT_ACCOUNT).putExtra("id", account.id));
}
}
AdapterAccount(Context context) {
this.context = context;
setHasStableIds(true);
}
public void set(@NonNull List<EntityAccount> accounts) {
Log.i(Helper.TAG, "Set accounts=" + accounts.size());
final Collator collator = Collator.getInstance(Locale.getDefault());
collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc
Collections.sort(
accounts,
new Comparator<EntityAccount>() {
@Override
public int compare(EntityAccount a1, EntityAccount a2) {
return collator.compare(a1.host, a2.host);
}
});
all = accounts;
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<EntityAccount> prev;
private List<EntityAccount> next;
MessageDiffCallback(List<EntityAccount> prev, List<EntityAccount> next) {
this.prev = prev;
this.next = next;
}
@Override
public int getItemCount() {
return filtered.size();
public int getOldListSize() {
return prev.size();
}
@Override
@NonNull
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new ViewHolder(
LayoutInflater.from(context).inflate(R.layout.item_account, parent, false));
public int getNewListSize() {
return next.size();
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.unwire();
EntityAccount account = filtered.get(position);
holder.bindTo(account);
public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
EntityAccount f1 = prev.get(oldItemPosition);
EntityAccount f2 = next.get(newItemPosition);
return f1.id.equals(f2.id);
}
holder.wire();
@Override
public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
EntityAccount f1 = prev.get(oldItemPosition);
EntityAccount f2 = next.get(newItemPosition);
return f1.equals(f2);
}
}
@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_account, parent, false));
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.unwire();
EntityAccount account = filtered.get(position);
holder.bindTo(account);
holder.wire();
}
}
......@@ -39,157 +39,156 @@ import java.util.List;
import java.util.Locale;
public class AdapterAnswer extends RecyclerView.Adapter<AdapterAnswer.ViewHolder> {
private Context context;
private Context context;
private List<EntityAnswer> all = new ArrayList<>();
private List<EntityAnswer> filtered = new ArrayList<>();
private List<EntityAnswer> all = new ArrayList<>();
private List<EntityAnswer> filtered = new ArrayList<>();
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
View itemView;
TextView tvName;
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
View itemView;
TextView tvName;
ViewHolder(View itemView) {
super(itemView);
ViewHolder(View itemView) {
super(itemView);
this.itemView = itemView;
tvName = itemView.findViewById(R.id.tvName);
}
private void wire() {
itemView.setOnClickListener(this);
}
private void unwire() {
itemView.setOnClickListener(null);
}
private void bindTo(EntityAnswer answer) {
tvName.setText(answer.name);
}
@Override
public void onClick(View v) {
int pos = getAdapterPosition();
if (pos == RecyclerView.NO_POSITION) {
return;
}
EntityAnswer answer = filtered.get(pos);
this.itemView = itemView;
tvName = itemView.findViewById(R.id.tvName);
}
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_EDIT_ANSWER).putExtra("id", answer.id));
}
private void wire() {
itemView.setOnClickListener(this);
}
AdapterAnswer(Context context) {
this.context = context;
setHasStableIds(true);
private void unwire() {
itemView.setOnClickListener(null);
}
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 = 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 void bindTo(EntityAnswer answer) {
tvName.setText(answer.name);
}
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 void onClick(View v) {
int pos = getAdapterPosition();
if (pos == RecyclerView.NO_POSITION) {
return;
}
EntityAnswer answer = filtered.get(pos);
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(new Intent(ActivityView.ACTION_EDIT_ANSWER).putExtra("id", answer.id));
}
}
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 = 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 long getItemId(int position) {
return filtered.get(position).id;
public int getOldListSize() {
return prev.size();
}
@Override
public int getItemCount() {
return filtered.size();
public int getNewListSize() {
return next.size();
}
@Override
@NonNull
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new ViewHolder(
LayoutInflater.from(context).inflate(R.layout.item_answer, parent, false));
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 void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.unwire();
EntityAnswer answer = filtered.get(position);
holder.bindTo(answer);
holder.wire();
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_answer, parent, false));
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.unwire();
EntityAnswer answer = filtered.get(position);
holder.bindTo(answer);
holder.wire();
}
}