[android] Replaced custom date formatter with system one

This commit is contained in:
Александр Зацепин 2018-02-14 18:16:45 +03:00 committed by Roman Kuznetsov
parent 8dc9c49b2e
commit 7293c8e76a
5 changed files with 41 additions and 29 deletions

View file

@ -8,16 +8,12 @@ import android.view.View;
import com.mapswithme.maps.Framework;
import com.mapswithme.maps.R;
import com.mapswithme.maps.widget.BookmarkBackupView;
import com.mapswithme.util.DateUtils;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class BookmarkBackupController
{
private static final DateFormat DATE_FORMATTER = new SimpleDateFormat("dd.MM.yyyy",
Locale.getDefault());
@NonNull
private final BookmarkBackupView mBackupView;
@Nullable
@ -68,7 +64,7 @@ public class BookmarkBackupController
if (backupTime > 0)
{
msg = context.getString(R.string.bookmarks_message_backuped_user,
DATE_FORMATTER.format(new Date(backupTime)));
DateUtils.getMediumDateFormat().format(new Date(backupTime)));
}
else
{

View file

@ -26,28 +26,26 @@ import com.mapswithme.maps.widget.ToolbarController;
import com.mapswithme.maps.widget.recycler.TagItemDecoration;
import com.mapswithme.maps.widget.recycler.TagLayoutManager;
import com.mapswithme.util.ConnectionState;
import com.mapswithme.util.DateUtils;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.statistics.Statistics;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
public class FilterFragment extends BaseMwmToolbarFragment
implements HotelsTypeAdapter.OnTypeSelectedListener
{
static final DateFormat DATE_FORMATTER = new SimpleDateFormat("EEE, MMM d", Locale.getDefault());
static final String ARG_FILTER = "arg_filter";
static final String ARG_FILTER_PARAMS = "arg_filter_params";
private static final int MAX_STAYING_DAYS = 30;
private static final int MAX_CHECKIN_WINDOW_IN_DAYS = 360;
@NonNull
private final DateFormat mDateFormatter = DateUtils.getMediumDateFormat();
@Nullable
private CustomNavigateUpListener mNavigateUpListener;
@Nullable
@ -89,7 +87,7 @@ public class FilterFragment extends BaseMwmToolbarFragment
if (mCheckinDate.after(mCheckoutDate))
{
mCheckoutDate = getDayAfter(mCheckinDate);
mCheckOut.setText(DATE_FORMATTER.format(mCheckoutDate.getTime()));
mCheckOut.setText(mDateFormatter.format(mCheckoutDate.getTime()));
}
else
{
@ -98,10 +96,10 @@ public class FilterFragment extends BaseMwmToolbarFragment
if (days > MAX_STAYING_DAYS)
{
mCheckoutDate = getMaxDateForCheckout(mCheckinDate);
mCheckOut.setText(DATE_FORMATTER.format(mCheckoutDate.getTime()));
mCheckOut.setText(mDateFormatter.format(mCheckoutDate.getTime()));
}
}
mCheckIn.setText(DATE_FORMATTER.format(chosenDate.getTime()));
mCheckIn.setText(mDateFormatter.format(chosenDate.getTime()));
};
@NonNull
private final DatePickerDialog.OnDateSetListener mCheckoutListener = (view, year, monthOfYear,
@ -110,7 +108,7 @@ public class FilterFragment extends BaseMwmToolbarFragment
Calendar chosenDate = Calendar.getInstance();
chosenDate.set(year, monthOfYear, dayOfMonth);
mCheckoutDate = chosenDate;
mCheckOut.setText(DATE_FORMATTER.format(mCheckoutDate.getTime()));
mCheckOut.setText(mDateFormatter.format(mCheckoutDate.getTime()));
};
@NonNull
private final BroadcastReceiver mNetworkStateReceiver = new BroadcastReceiver()
@ -392,21 +390,21 @@ public class FilterFragment extends BaseMwmToolbarFragment
if (params == null)
{
mCheckinDate = Calendar.getInstance();
mCheckIn.setText(DATE_FORMATTER.format(mCheckinDate.getTime()));
mCheckIn.setText(mDateFormatter.format(mCheckinDate.getTime()));
mCheckoutDate = getDayAfter(mCheckinDate);
mCheckOut.setText(DATE_FORMATTER.format(mCheckoutDate.getTime()));
mCheckOut.setText(mDateFormatter.format(mCheckoutDate.getTime()));
}
else
{
Calendar checkin = Calendar.getInstance();
checkin.setTimeInMillis(params.getCheckinMillisec());
mCheckinDate = checkin;
mCheckIn.setText(DATE_FORMATTER.format(mCheckinDate.getTime()));
mCheckIn.setText(mDateFormatter.format(mCheckinDate.getTime()));
Calendar checkout = Calendar.getInstance();
checkout.setTimeInMillis(params.getCheckoutMillisec());
mCheckoutDate = checkout;
mCheckOut.setText(DATE_FORMATTER.format(mCheckoutDate.getTime()));
mCheckOut.setText(mDateFormatter.format(mCheckoutDate.getTime()));
}
}

View file

@ -11,15 +11,16 @@ import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.mapswithme.maps.R;
import com.mapswithme.maps.bookmarks.data.MapObject;
import com.mapswithme.maps.widget.RatingView;
import com.mapswithme.maps.widget.placepage.PlacePageView;
import com.mapswithme.maps.widget.recycler.ItemDecoratorFactory;
import com.mapswithme.util.DateUtils;
import com.mapswithme.util.UiUtils;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -269,11 +270,12 @@ public class UGCController implements View.OnClickListener, UGC.UGCListener
mUserRatingRecordsContainer);
if (update == null)
return;
TextView name = (TextView) mUserReviewView.findViewById(R.id.name);
TextView date = (TextView) mUserReviewView.findViewById(R.id.date);
TextView name = mUserReviewView.findViewById(R.id.name);
TextView date = mUserReviewView.findViewById(R.id.date);
name.setText(R.string.placepage_reviews_your_comment);
date.setText(UGCReviewAdapter.DATE_FORMATTER.format(new Date(update.getTimeMillis())));
TextView review = (TextView) mUserReviewView.findViewById(R.id.review);
DateFormat formatter = DateUtils.getMediumDateFormat();
date.setText(formatter.format(new Date(update.getTimeMillis())));
TextView review = mUserReviewView.findViewById(R.id.review);
UiUtils.showIf(!TextUtils.isEmpty(update.getText()), review);
review.setText(update.getText());
mUGCUserRatingRecordsAdapter.setItems(update.getRatings());

View file

@ -10,18 +10,15 @@ import android.widget.TextView;
import com.mapswithme.maps.R;
import com.mapswithme.maps.widget.RatingView;
import com.mapswithme.util.DateUtils;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
class UGCReviewAdapter extends Adapter<UGCReviewAdapter.ViewHolder>
{
static final int MAX_COUNT = 3;
static final DateFormat DATE_FORMATTER = new SimpleDateFormat("dd MMMM yyyy", Locale.getDefault());
@NonNull
private ArrayList<UGC.Review> mItems = new ArrayList<>();
@ -76,7 +73,7 @@ class UGCReviewAdapter extends Adapter<UGCReviewAdapter.ViewHolder>
public void bind(UGC.Review review)
{
mAuthor.setText(review.getAuthor());
mCommentDate.setText(DATE_FORMATTER.format(new Date(review.getTime())));
mCommentDate.setText(DateUtils.getMediumDateFormat().format(new Date(review.getTime())));
mReview.setText(review.getText());
mRating.setRating(Impress.values()[review.getImpress()], String.valueOf(review.getRating()));
}

View file

@ -0,0 +1,19 @@
package com.mapswithme.util;
import android.support.annotation.NonNull;
import java.text.DateFormat;
import java.util.Locale;
public class DateUtils
{
private DateUtils()
{
}
@NonNull
public static DateFormat getMediumDateFormat()
{
return DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault());
}
}