Relative date in blacklist, stats in item edit
This commit is contained in:
parent
a5af1bc9aa
commit
8e44b20e15
|
@ -2,6 +2,7 @@ package dummydomain.yetanothercallblocker;
|
|||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.text.format.DateUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
@ -17,7 +18,7 @@ import androidx.recyclerview.selection.ItemKeyProvider;
|
|||
import androidx.recyclerview.selection.SelectionTracker;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import dummydomain.yetanothercallblocker.data.db.BlacklistItem;
|
||||
|
@ -91,7 +92,6 @@ public class BlacklistItemRecyclerViewAdapter extends GenericRecyclerViewAdapter
|
|||
|
||||
final TextView name, pattern, stats;
|
||||
final AppCompatImageView errorIcon;
|
||||
final DateFormat dateFormat, timeFormat;
|
||||
|
||||
ItemDetailsLookup.ItemDetails<Long> itemDetails;
|
||||
|
||||
|
@ -102,9 +102,6 @@ public class BlacklistItemRecyclerViewAdapter extends GenericRecyclerViewAdapter
|
|||
pattern = itemView.findViewById(R.id.pattern);
|
||||
stats = itemView.findViewById(R.id.stats);
|
||||
errorIcon = itemView.findViewById(R.id.errorIcon);
|
||||
|
||||
dateFormat = android.text.format.DateFormat.getMediumDateFormat(itemView.getContext());
|
||||
timeFormat = android.text.format.DateFormat.getTimeFormat(itemView.getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -118,9 +115,10 @@ public class BlacklistItemRecyclerViewAdapter extends GenericRecyclerViewAdapter
|
|||
stats.setVisibility(View.VISIBLE);
|
||||
|
||||
Context context = stats.getContext();
|
||||
String dateString = item.getLastCallDate() != null
|
||||
? dateFormat.format(item.getLastCallDate()) + ' '
|
||||
+ timeFormat.format(item.getLastCallDate())
|
||||
|
||||
Date lastCallDate = item.getLastCallDate();
|
||||
String dateString = lastCallDate != null
|
||||
? DateUtils.getRelativeTimeSpanString(lastCallDate.getTime()).toString()
|
||||
: context.getString(R.string.blacklist_item_date_no_info);
|
||||
|
||||
stats.setText(context.getResources().getQuantityString(
|
||||
|
|
|
@ -8,8 +8,10 @@ import android.text.TextUtils;
|
|||
import android.text.TextWatcher;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
@ -19,7 +21,9 @@ import com.google.android.material.textfield.TextInputLayout;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
import dummydomain.yetanothercallblocker.data.BlacklistService;
|
||||
|
@ -72,6 +76,7 @@ public class EditBlacklistItemActivity extends AppCompatActivity {
|
|||
|
||||
nameTextField = findViewById(R.id.nameTextField);
|
||||
patternTextField = findViewById(R.id.patternTextField);
|
||||
TextView statsTextView = findViewById(R.id.stats);
|
||||
|
||||
EditText patternEditText = Objects.requireNonNull(patternTextField.getEditText());
|
||||
patternEditText.addTextChangedListener(new TextWatcher() {
|
||||
|
@ -127,6 +132,29 @@ public class EditBlacklistItemActivity extends AppCompatActivity {
|
|||
setString(patternTextField, pattern);
|
||||
}
|
||||
|
||||
if (blacklistItem != null) {
|
||||
String statsString;
|
||||
if (blacklistItem.getNumberOfCalls() > 0) {
|
||||
DateFormat dateFormat = android.text.format.DateFormat.getMediumDateFormat(this);
|
||||
DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(this);
|
||||
|
||||
Date lastCallDate = blacklistItem.getLastCallDate();
|
||||
String dateString = lastCallDate != null
|
||||
? dateFormat.format(lastCallDate) + ' '
|
||||
+ timeFormat.format(lastCallDate)
|
||||
: getString(R.string.blacklist_item_date_no_info);
|
||||
|
||||
statsString = getResources().getQuantityString(
|
||||
R.plurals.blacklist_item_stats, blacklistItem.getNumberOfCalls(),
|
||||
blacklistItem.getNumberOfCalls(), dateString);
|
||||
} else {
|
||||
statsString = getString(R.string.blacklist_item_no_calls);
|
||||
}
|
||||
statsTextView.setText(statsString);
|
||||
} else {
|
||||
statsTextView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
patternTextField.requestFocus();
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
android:id="@+id/patternTextField"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/item_padding"
|
||||
android:hint="@string/edit_blacklist_item_number_pattern">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
|
@ -46,6 +47,14 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:text="@string/number_pattern_hint" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/stats"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/item_padding"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
tools:text="3 calls, last: Aug 01, 2020 10:10" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
android:id="@+id/stats"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="3 calls, last: Aug 01, 2020 10:10" />
|
||||
tools:text="3 calls, last: 3 days ago" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
@ -129,6 +129,7 @@
|
|||
<item quantity="many">%1$d звонков, последний: %2$s</item>
|
||||
</plurals>
|
||||
<string name="blacklist_item_date_no_info">нет информации</string>
|
||||
<string name="blacklist_item_no_calls">Никогда не звонил</string>
|
||||
<string name="blacklist_add">Добавить</string>
|
||||
<string name="blacklist_delete">Удалить</string>
|
||||
<string name="blacklist_delete_confirmation">Удалить выбранные элементы?</string>
|
||||
|
|
|
@ -140,6 +140,7 @@
|
|||
<item quantity="other">%1$d calls, last: %2$s</item>
|
||||
</plurals>
|
||||
<string name="blacklist_item_date_no_info">no info</string>
|
||||
<string name="blacklist_item_no_calls">Never called</string>
|
||||
<string name="blacklist_add">Add</string>
|
||||
<string name="blacklist_delete">Delete</string>
|
||||
<string name="blacklist_delete_confirmation">Delete the selected items?</string>
|
||||
|
|
Loading…
Reference in New Issue