Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f4c9999368 | ||
|
|
b681689f09 |
@@ -88,7 +88,7 @@ android {
|
||||
applicationId "com.mowesta.android.app"
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 29
|
||||
versionCode 4
|
||||
versionCode 5
|
||||
versionName "${version}"
|
||||
buildConfigField "long", "BUILD_TIME", System.currentTimeMillis() + "L"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
+134
-9
@@ -1,10 +1,8 @@
|
||||
package com.mowesta.android.app.fragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
@@ -28,6 +26,7 @@ import com.mowesta.android.app.model.CityViewModel;
|
||||
import com.mowesta.android.app.model.ConditionViewModel;
|
||||
import com.mowesta.android.app.model.SummaryViewModel;
|
||||
import com.mowesta.android.app.util.TabletUtil;
|
||||
import com.mowesta.android.feign.model.WeatherCondition;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -51,7 +50,23 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
ViewPager2 pager = view.findViewById(R.id.pager);
|
||||
CityViewModel model = getCityViewModel();
|
||||
pager.setAdapter(new ForecastAdapter(this));
|
||||
model.getNavigation().observe(getViewLifecycleOwner(), (request) -> {
|
||||
if (request != null) {
|
||||
switch (request.getType()) {
|
||||
case DAY:
|
||||
pager.setCurrentItem(0, true);
|
||||
break;
|
||||
case TIME:
|
||||
pager.setCurrentItem(1, true);
|
||||
break;
|
||||
case HOUR:
|
||||
pager.setCurrentItem(2, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
TabLayout tabs = view.findViewById(R.id.tabs);
|
||||
new TabLayoutMediator(tabs, pager, (tab, position) -> {
|
||||
switch (position) {
|
||||
@@ -105,6 +120,9 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
|
||||
*/
|
||||
public static class ForecastRecyclerFragment extends CityFragment.ChildFragment {
|
||||
|
||||
/** A handler to post updates. */
|
||||
private Handler handler = new Handler();
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
@@ -121,20 +139,107 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
|
||||
switch (page) {
|
||||
case 0:
|
||||
TabletUtil.setGridLayout(recyclerView, 400);
|
||||
recyclerView.setAdapter(new SummaryAdapter(getViewLifecycleOwner(), getCityViewModel().getDay()));
|
||||
recyclerView.setAdapter(new SummaryAdapter(getViewLifecycleOwner(), model.getDay(), (summary) -> {
|
||||
if (summary == null || summary.getFirstCondition() == null) return;
|
||||
long time = summary.getFirstCondition().getTime();
|
||||
List<SummaryViewModel> models = model.getTime().getValue();
|
||||
for (int i = 0; i < models.size(); i++) {
|
||||
SummaryViewModel s = models.get(i);
|
||||
if (s.getFirstCondition() != null && s.getFirstCondition().getTime() == time) {
|
||||
model.getNavigation().setValue(new CityViewModel.NavigationRequest(CityViewModel.NavigationRequest.ListType.TIME, i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}));
|
||||
model.getNavigation().observe(getViewLifecycleOwner(), (request) -> {
|
||||
if (request == null) return;
|
||||
if (request.getType() == CityViewModel.NavigationRequest.ListType.DAY) {
|
||||
recyclerView.post(() -> {
|
||||
scrollRecyclerViewToPosition(recyclerView, request.getPosition());
|
||||
model.getNavigation().setValue(null);
|
||||
});
|
||||
}
|
||||
});
|
||||
break;
|
||||
case 1:
|
||||
TabletUtil.setGridLayout(recyclerView, 400);
|
||||
recyclerView.setAdapter(new SummaryAdapter(getViewLifecycleOwner(), getCityViewModel().getTime()));
|
||||
recyclerView.setAdapter(new SummaryAdapter(getViewLifecycleOwner(), model.getTime(), (summary) -> {
|
||||
if (summary == null || summary.getFirstCondition() == null) return;
|
||||
long time = summary.getFirstCondition().getTime();
|
||||
List<ConditionViewModel> models = model.getHour().getValue();
|
||||
for (int i = 0; i < models.size(); i++) {
|
||||
ConditionViewModel c = models.get(i);
|
||||
WeatherCondition wc = c.getCondition().getValue();
|
||||
if (wc != null && wc.getTime() == time) {
|
||||
model.getNavigation().setValue(new CityViewModel.NavigationRequest(CityViewModel.NavigationRequest.ListType.HOUR, i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}));
|
||||
model.getNavigation().observe(getViewLifecycleOwner(), (request) -> {
|
||||
if (request == null) return;
|
||||
if (request.getType() == CityViewModel.NavigationRequest.ListType.TIME) {
|
||||
recyclerView.post(() -> {
|
||||
scrollRecyclerViewToPosition(recyclerView, request.getPosition());
|
||||
model.getNavigation().setValue(null);
|
||||
});
|
||||
}
|
||||
});
|
||||
break;
|
||||
default:
|
||||
TabletUtil.setGridLayout(recyclerView, 250);
|
||||
recyclerView.setAdapter(new ConditionAdapter(getViewLifecycleOwner(), getCityViewModel().getHour()));
|
||||
TabletUtil.setGridLayout(recyclerView, 300);
|
||||
recyclerView.setAdapter(new ConditionAdapter(getViewLifecycleOwner(), getCityViewModel().getHour(), (condition) -> {
|
||||
if (condition == null || condition.getCondition().getValue() == null) return;
|
||||
long time = condition.getCondition().getValue().getTime();
|
||||
List<SummaryViewModel> models = model.getDay().getValue();
|
||||
for (int i = 0; i < models.size(); i++) {
|
||||
SummaryViewModel s = models.get(i);
|
||||
if (s.getFirstCondition() != null && s.getLastCondition() != null
|
||||
&& s.getLastCondition().getTime() >= time && s.getFirstCondition().getTime() <= time) {
|
||||
model.getNavigation().setValue(new CityViewModel.NavigationRequest(CityViewModel.NavigationRequest.ListType.DAY, i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}));
|
||||
model.getNavigation().observe(getViewLifecycleOwner(), (request) -> {
|
||||
if (request == null) return;
|
||||
if (request.getType() == CityViewModel.NavigationRequest.ListType.HOUR) {
|
||||
recyclerView.post(() -> {
|
||||
scrollRecyclerViewToPosition(recyclerView, request.getPosition());
|
||||
model.getNavigation().setValue(null);
|
||||
});
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Scrolls a recycler view to the specified position using a smooth scroll effect
|
||||
* that ist limited in motion.
|
||||
*
|
||||
* @param view The view.
|
||||
* @param position The position.
|
||||
*/
|
||||
private static void scrollRecyclerViewToPosition(RecyclerView view, int position) {
|
||||
GridLayoutManager layout = (GridLayoutManager)view.getLayoutManager();
|
||||
int current = layout.findFirstVisibleItemPosition();
|
||||
int last = layout.findLastVisibleItemPosition();
|
||||
int diff = Math.max(1, last - current) * 3;
|
||||
if (Math.abs(current - position) > diff) {
|
||||
if (current < position) current = position - diff;
|
||||
else current = position + diff;
|
||||
}
|
||||
view.scrollToPosition(current);
|
||||
view.post(() -> {
|
||||
view.smoothScrollToPosition(position);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A recycler view adapter that can display a list of weather summaries.
|
||||
*
|
||||
@@ -150,10 +255,22 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
|
||||
* The live data that provides updates.
|
||||
*/
|
||||
private LiveData<List<SummaryViewModel>> model;
|
||||
/**
|
||||
* The click listener for the summary model.
|
||||
*/
|
||||
private SummaryViewModel.OnSummarySelectedListener listener;
|
||||
|
||||
public SummaryAdapter(LifecycleOwner lifecycleOwner, LiveData<List<SummaryViewModel>> model) {
|
||||
/**
|
||||
* Creates a new adapter.
|
||||
*
|
||||
* @param lifecycleOwner The lifecycle owner.
|
||||
* @param model The model to observe.
|
||||
* @param listener The listener to handle clicks.
|
||||
*/
|
||||
public SummaryAdapter(LifecycleOwner lifecycleOwner, LiveData<List<SummaryViewModel>> model, SummaryViewModel.OnSummarySelectedListener listener) {
|
||||
this.lifecycleOwner = lifecycleOwner;
|
||||
this.model = model;
|
||||
this.listener = listener;
|
||||
this.model.observe(lifecycleOwner, (data)-> {
|
||||
this.notifyDataSetChanged();
|
||||
});
|
||||
@@ -164,6 +281,7 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
|
||||
public SummaryViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
ViewSummaryBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.view_summary, parent, false);
|
||||
binding.setLifecycleOwner(lifecycleOwner);
|
||||
binding.setListener(listener);
|
||||
SummaryViewHolder holder = new SummaryViewHolder(binding);
|
||||
return holder;
|
||||
}
|
||||
@@ -231,15 +349,21 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
|
||||
*/
|
||||
private LiveData<List<ConditionViewModel>> model;
|
||||
|
||||
/**
|
||||
* The listener for the cards.
|
||||
*/
|
||||
private ConditionViewModel.OnConditionSelectedListener listener;
|
||||
|
||||
/**
|
||||
* Creates a new adapter for weather conditions.
|
||||
*
|
||||
* @param lifecycleOwner The lifecycle owner.
|
||||
* @param model The list of weather conditions to show.
|
||||
*/
|
||||
public ConditionAdapter(LifecycleOwner lifecycleOwner, LiveData<List<ConditionViewModel>> model) {
|
||||
public ConditionAdapter(LifecycleOwner lifecycleOwner, LiveData<List<ConditionViewModel>> model, ConditionViewModel.OnConditionSelectedListener listener) {
|
||||
this.lifecycleOwner = lifecycleOwner;
|
||||
this.model = model;
|
||||
this.listener = listener;
|
||||
this.model.observe(lifecycleOwner, (data)-> {
|
||||
this.notifyDataSetChanged();
|
||||
});
|
||||
@@ -250,6 +374,7 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
|
||||
public ConditionViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
ViewConditionBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.view_condition, parent, false);
|
||||
binding.setLifecycleOwner(lifecycleOwner);
|
||||
binding.setListener(listener);
|
||||
ConditionViewHolder holder = new ConditionViewHolder(binding);
|
||||
return holder;
|
||||
}
|
||||
|
||||
@@ -46,6 +46,12 @@ public class CityInfoFragment extends CityFragment.ChildFragment {
|
||||
FragmentCityInfoBinding binding = DataBindingUtil.inflate(inflater, R.layout.fragment_city_info, container, false);
|
||||
MapView mapView = binding.getRoot().findViewById(R.id.map_detail);
|
||||
MapViewUtil.setupInteractiveMap(mapView);
|
||||
// reduce brightness of map (technically, we should generate a night mode in leafless but this needs to be fixed in the library)
|
||||
if (getResources().getBoolean(R.bool.dark_mode)) {
|
||||
mapView.setAlpha(0.5f);
|
||||
} else {
|
||||
mapView.setAlpha(1f);
|
||||
}
|
||||
CityViewModel model = new ViewModelProvider(getParentFragment().getParentFragment()).get(CityViewModel.class);
|
||||
ConditionViewModel condition = new ViewModelProvider(this).get(ConditionViewModel.class);
|
||||
Runnable updateCondition = () -> {
|
||||
@@ -77,7 +83,7 @@ public class CityInfoFragment extends CityFragment.ChildFragment {
|
||||
model.getBoundary().observe(getViewLifecycleOwner(), (b) -> updateMap.run());
|
||||
binding.setModel(model);
|
||||
binding.setCondition(condition);
|
||||
NavController controller = Navigation.findNavController(getActivity(), R.id.navigation_app);
|
||||
NavController appController = Navigation.findNavController(getActivity(), R.id.navigation_app);
|
||||
binding.setStationListener(new CityViewModel.OnStationSelectedListener() {
|
||||
@Override
|
||||
public void onStationSelected(WeatherStation station) {
|
||||
@@ -85,9 +91,15 @@ public class CityInfoFragment extends CityFragment.ChildFragment {
|
||||
NavOptions.Builder opts = new NavOptions.Builder().setEnterAnim(R.anim.slide_in_right).setExitAnim(R.anim.slide_out_left);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong("id", station.getId());
|
||||
controller.navigate(R.id.destination_station, bundle, opts.build());
|
||||
appController.navigate(R.id.destination_station, bundle, opts.build());
|
||||
}
|
||||
});
|
||||
System.out.println("XXXX");
|
||||
NavController cityController = Navigation.findNavController(getActivity(), R.id.navigation_city);
|
||||
binding.setConditionListener(m -> {
|
||||
System.out.println("here");
|
||||
cityController.navigate(R.id.destination_city_forecast);
|
||||
});
|
||||
binding.setLifecycleOwner(getViewLifecycleOwner());
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
@@ -211,13 +212,7 @@ public class VideoFragment extends Fragment {
|
||||
double hps = video.getFph() / (double)video.getFps();
|
||||
long hours = (long)(secs / hps);
|
||||
long time = video.getTime() + (video.getStart() + hours) * 60 * 60 * 1000;
|
||||
int dayRes = timeUtils.getDayName(time);
|
||||
String day;
|
||||
if (dayRes != 0) {
|
||||
day = getString(dayRes);
|
||||
} else {
|
||||
day = formatter.asDate(time, timezone);
|
||||
}
|
||||
String day = timeUtils.getDayName(getContext(), time);
|
||||
String hour = formatter.asTime(time, timezone);
|
||||
overlay.setText(getResources().getString(R.string.format_two_lines, day, hour));
|
||||
handler.postDelayed(this.timer, 500);
|
||||
@@ -293,6 +288,7 @@ public class VideoFragment extends Fragment {
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
if (video != null) {
|
||||
handler.postDelayed(timer, 500);
|
||||
if (model.markerX != null && model.markerY != null) {
|
||||
@@ -307,6 +303,7 @@ public class VideoFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
marker.removeOnLayoutChangeListener(markerListener);
|
||||
handler.removeCallbacks(timer);
|
||||
super.onPause();
|
||||
|
||||
@@ -575,7 +575,7 @@ public class BindingAdapters {
|
||||
}
|
||||
|
||||
@BindingAdapter("datetime")
|
||||
public static void setGuidelinePosition(@NonNull TextView textView, @Nullable DiagramEntry<?> entry) {
|
||||
public static void setDiagramDateTime(@NonNull TextView textView, @Nullable DiagramEntry<?> entry) {
|
||||
if (entry == null) {
|
||||
textView.setText("");
|
||||
} else {
|
||||
|
||||
@@ -48,6 +48,52 @@ public class CityViewModel extends AbstractPlaceViewModel {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A navigation request caused by a click on a summary.
|
||||
*/
|
||||
public static class NavigationRequest {
|
||||
/** The view types to navigate to. */
|
||||
public enum ListType { DAY, TIME, HOUR }
|
||||
|
||||
/** The list type to navigate to. */
|
||||
private @NonNull ListType type;
|
||||
/** The condition to navigate to. */
|
||||
private @NonNull int position;
|
||||
|
||||
/**
|
||||
* Creates a new request.
|
||||
*
|
||||
* @param type The type.
|
||||
* @param position The position.
|
||||
*/
|
||||
public NavigationRequest(@NonNull ListType type, @NonNull int position) {
|
||||
this.type = type;
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list type to navigate to.
|
||||
*
|
||||
* @return The type.
|
||||
*/
|
||||
@NonNull
|
||||
public ListType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the position to navigate to.
|
||||
*
|
||||
* @return The position.
|
||||
*/
|
||||
@NonNull
|
||||
public int getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The current weather condition.
|
||||
*/
|
||||
@@ -108,6 +154,11 @@ public class CityViewModel extends AbstractPlaceViewModel {
|
||||
*/
|
||||
private final MutableLiveData<Geometry> boundary = new MutableLiveData<>();
|
||||
|
||||
/**
|
||||
* The livedata to handle navigation between the different forecast fragments.
|
||||
*/
|
||||
private final MutableLiveData<NavigationRequest> navigation = new MutableLiveData<>();
|
||||
|
||||
/**
|
||||
* The loader for the city data.
|
||||
*/
|
||||
@@ -186,6 +237,7 @@ public class CityViewModel extends AbstractPlaceViewModel {
|
||||
super(application);
|
||||
id.observeForever((value) -> {
|
||||
long code = newRequestCode();
|
||||
navigation.setValue(null);
|
||||
favorite.setValue(null);
|
||||
forecast.setValue(null);
|
||||
city.setValue(null);
|
||||
@@ -220,6 +272,15 @@ public class CityViewModel extends AbstractPlaceViewModel {
|
||||
return favorite;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the navigation live data to handle transition between views.
|
||||
*
|
||||
* @return The navigation.
|
||||
*/
|
||||
public MutableLiveData<NavigationRequest> getNavigation() {
|
||||
return navigation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the city.
|
||||
*
|
||||
@@ -394,8 +455,10 @@ public class CityViewModel extends AbstractPlaceViewModel {
|
||||
for (WeatherCondition c: wc) {
|
||||
long end = d.getEnd(c);
|
||||
ConditionViewModel vm = new ConditionViewModel(getApplication());
|
||||
int title = d.getDayName(c.getTime());
|
||||
vm.setData(title == 0 ? null: getApplication().getString(title), null, c, tz);
|
||||
long time = c.getTime();
|
||||
String title = d.getDayName(getApplication(), time);
|
||||
String subtitle = getApplication().getString(R.string.format_two_parts, df.asTime(time, tz), df.asDate(time, tz));
|
||||
vm.setData(title, subtitle, c, tz);
|
||||
hours.add(vm);
|
||||
if (currentDay == null) {
|
||||
currentDay = new ArrayList<>();
|
||||
@@ -437,9 +500,7 @@ public class CityViewModel extends AbstractPlaceViewModel {
|
||||
List<SummaryViewModel> models = new ArrayList<>();
|
||||
for (List<WeatherCondition> ds: days) {
|
||||
long time = d.getTime(ds);
|
||||
String title = df.asDate(time, tz);
|
||||
int res = d.getDayName(time);
|
||||
if (res != 0) title = getApplication().getString(res);
|
||||
String title = d.getDayName(getApplication(), time);
|
||||
SummaryViewModel summary = new SummaryViewModel(getApplication());
|
||||
WeatherCondition[] data = new WeatherCondition[ds.size()];
|
||||
data = ds.toArray(data);
|
||||
@@ -450,9 +511,7 @@ public class CityViewModel extends AbstractPlaceViewModel {
|
||||
models = new ArrayList<>();
|
||||
for (List<WeatherCondition> ts: times) {
|
||||
long time = d.getTime(ts);
|
||||
String title = df.asDate(time, tz);
|
||||
int res = d.getDayName(time);
|
||||
if (res != 0) title = getApplication().getString(res);
|
||||
String title = d.getDayName(getApplication(), time);
|
||||
int slot = d.getSlotName(time);
|
||||
SummaryViewModel summary = new SummaryViewModel(getApplication());
|
||||
WeatherCondition[] data = new WeatherCondition[ts.size()];
|
||||
|
||||
@@ -18,6 +18,21 @@ import com.mowesta.android.feign.model.WeatherCondition;
|
||||
*/
|
||||
public class ConditionViewModel extends CustomizeViewModel {
|
||||
|
||||
/**
|
||||
* A click listener for weather condition cards.
|
||||
*/
|
||||
public interface OnConditionSelectedListener {
|
||||
|
||||
/**
|
||||
* Called when the condition is selected.
|
||||
*
|
||||
* @param model The condition that has been clicked.
|
||||
*/
|
||||
void onConditionSelected(ConditionViewModel model);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The title to display.
|
||||
*/
|
||||
|
||||
@@ -18,6 +18,19 @@ import com.mowesta.android.feign.model.WeatherCondition;
|
||||
*/
|
||||
public class SummaryViewModel extends CustomizeViewModel {
|
||||
|
||||
/**
|
||||
* A click listener for the summary view model.
|
||||
*/
|
||||
public interface OnSummarySelectedListener {
|
||||
/**
|
||||
* Called when the summary is selected.
|
||||
*
|
||||
* @param model The model with the summary.
|
||||
*/
|
||||
void onSummarySelected(SummaryViewModel model);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The minimum values.
|
||||
*/
|
||||
@@ -127,6 +140,29 @@ public class SummaryViewModel extends CustomizeViewModel {
|
||||
updateSubtitle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first condition contained in the data or null.
|
||||
*
|
||||
* @return The first condition or null.
|
||||
*/
|
||||
@Nullable
|
||||
public WeatherCondition getFirstCondition() {
|
||||
if (conditions == null || conditions.length < 1) return null;
|
||||
return conditions[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last condition contained in the data or null.
|
||||
*
|
||||
* @return The last condition contained in the data.
|
||||
*/
|
||||
@Nullable
|
||||
public WeatherCondition getLastCondition() {
|
||||
if (conditions == null || conditions.length < 1) return null;
|
||||
return conditions[conditions.length - 1];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines whether the min and max values are set.
|
||||
*
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
package com.mowesta.android.app.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.content.res.ResourcesCompat;
|
||||
import androidx.core.os.ConfigurationCompat;
|
||||
|
||||
import com.mowesta.android.app.R;
|
||||
import com.mowesta.android.feign.model.WeatherCondition;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
@@ -49,20 +58,25 @@ public class TimeUtils {
|
||||
/**
|
||||
* Returns the resource id of the "special" day.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param time The time.
|
||||
* @return The day name.
|
||||
*/
|
||||
public int getDayName(long time) {
|
||||
public String getDayName(Context context, long time) {
|
||||
c.setTimeInMillis(time);
|
||||
update(temp1);
|
||||
if (equals(temp1, yesterday)) {
|
||||
return R.string.date_yesterday;
|
||||
return context.getString(R.string.date_yesterday);
|
||||
} else if (equals(temp1, today)) {
|
||||
return R.string.date_today;
|
||||
return context.getString(R.string.date_today);
|
||||
} else if (equals(temp1, tomorrow)) {
|
||||
return R.string.date_tomorrow;
|
||||
return context.getString(R.string.date_tomorrow);
|
||||
} else {
|
||||
return 0;
|
||||
c.setTimeInMillis(time);
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("EEEE",
|
||||
ConfigurationCompat.getLocales(context.getResources().getConfiguration()).get(0));
|
||||
sdf.setCalendar(c);
|
||||
return sdf.format(new Date(time));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,17 +2,21 @@ package com.mowesta.android.app.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.DrawFilter;
|
||||
import android.text.TextPaint;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Gravity;
|
||||
|
||||
import androidx.appcompat.widget.AppCompatTextView;
|
||||
|
||||
import com.google.android.material.textview.MaterialTextView;
|
||||
|
||||
/**
|
||||
* A text view that draws vertical text.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class VerticalTextView extends AppCompatTextView {
|
||||
public class VerticalTextView extends MaterialTextView {
|
||||
|
||||
/**
|
||||
* The drawing direction.
|
||||
@@ -73,14 +77,23 @@ public class VerticalTextView extends AppCompatTextView {
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
TextPaint textPaint = getPaint();
|
||||
textPaint.setColor( getCurrentTextColor() );
|
||||
textPaint.drawableState = getDrawableState();
|
||||
canvas.save();
|
||||
if (topDown) {
|
||||
canvas.translate(getWidth(), 0);
|
||||
canvas.rotate(90);
|
||||
} else {
|
||||
canvas.translate(0, getHeight());
|
||||
canvas.rotate(-90);
|
||||
canvas.translate( 0, getHeight() );
|
||||
canvas.rotate( -90 );
|
||||
}
|
||||
canvas.translate(getCompoundPaddingLeft(), getExtendedPaddingTop());
|
||||
getLayout().draw(canvas);
|
||||
canvas.translate( getCompoundPaddingLeft(),
|
||||
getExtendedPaddingTop() );
|
||||
getLayout().draw( canvas );
|
||||
canvas.setDrawFilter(new DrawFilter() {
|
||||
|
||||
});
|
||||
canvas.restore();
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
<variable name="model" type="com.mowesta.android.app.model.CityViewModel" />
|
||||
<variable name="stationListener" type="com.mowesta.android.app.model.CityViewModel.OnStationSelectedListener" />
|
||||
<variable name="condition" type="com.mowesta.android.app.model.ConditionViewModel" />
|
||||
<variable name="conditionListener" type="com.mowesta.android.app.model.ConditionViewModel.OnConditionSelectedListener" />
|
||||
</data>
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
@@ -35,6 +36,7 @@
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
layout="@layout/view_condition"
|
||||
app:listener="@{conditionListener}"
|
||||
app:model="@{condition}" />
|
||||
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
<variable name="model" type="com.mowesta.android.app.model.CityViewModel" />
|
||||
<variable name="stationListener" type="com.mowesta.android.app.model.CityViewModel.OnStationSelectedListener" />
|
||||
<variable name="condition" type="com.mowesta.android.app.model.ConditionViewModel" />
|
||||
<variable name="conditionListener" type="com.mowesta.android.app.model.ConditionViewModel.OnConditionSelectedListener" />
|
||||
</data>
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
@@ -21,6 +22,7 @@
|
||||
|
||||
<include
|
||||
layout="@layout/view_condition"
|
||||
app:listener="@{conditionListener}"
|
||||
app:model="@{condition}" />
|
||||
|
||||
<include layout="@layout/view_city_detail"
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
app:boxBackgroundColor="@color/accent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:hintTextColor="@color/black"
|
||||
app:hintTextColor="?attr/colorControlNormal"
|
||||
app:endIconMode="clear_text"
|
||||
app:startIconDrawable="@drawable/ic_search_normal_24">
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
|
||||
@@ -7,11 +7,18 @@
|
||||
<variable
|
||||
name="model"
|
||||
type="com.mowesta.android.app.model.ConditionViewModel" />
|
||||
<variable
|
||||
name="listener"
|
||||
type="com.mowesta.android.app.model.ConditionViewModel.OnConditionSelectedListener" />
|
||||
</data>
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:onClick="@{ () -> listener.onConditionSelected(model) }"
|
||||
app:rippleColor="@color/accent"
|
||||
android:visibility="@{ (model.condition == null) ? View.GONE : View.VISIBLE }"
|
||||
app:cardElevation="4dp"
|
||||
android:layout_margin="8dp">
|
||||
|
||||
@@ -23,15 +23,15 @@
|
||||
tools:text="10.3.2020\n8.30"
|
||||
datetime="@{model}"
|
||||
android:gravity="center|bottom"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Caption"
|
||||
android:textAppearance="?attr/textAppearanceCaption"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="100dp"/>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="2dp"
|
||||
android:background="@color/black"/>
|
||||
android:layout_height="1dp"
|
||||
android:background="@color/inverse"/>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="36dp"
|
||||
|
||||
@@ -7,11 +7,18 @@
|
||||
<variable
|
||||
name="model"
|
||||
type="com.mowesta.android.app.model.SummaryViewModel" />
|
||||
<variable
|
||||
name="listener"
|
||||
type="com.mowesta.android.app.model.SummaryViewModel.OnSummarySelectedListener" />
|
||||
</data>
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:onClick="@{ () -> listener.onSummarySelected(model) }"
|
||||
app:rippleColor="@color/accent"
|
||||
app:cardElevation="4dp"
|
||||
android:layout_margin="8dp">
|
||||
|
||||
@@ -34,7 +41,7 @@
|
||||
weatherIcon="@{model.min}"
|
||||
android:textSize="40dp"/>
|
||||
<com.mowesta.android.app.view.WeatherView
|
||||
android:layout_width="80dp"
|
||||
android:layout_width="70dp"
|
||||
android:layout_height="60dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
|
||||
@@ -2,4 +2,5 @@
|
||||
<resources>
|
||||
<color name="separator">#555555</color>
|
||||
<color name="bg_search">#333333</color>
|
||||
<color name="inverse">#a0ffffff</color>
|
||||
</resources>
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<bool name="dark_mode">true</bool>
|
||||
|
||||
</resources>
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<style name="match_parent_limit">
|
||||
<item name="android:layout_width">520dp</item>
|
||||
<item name="android:layout_width">510dp</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
||||
@@ -9,4 +9,5 @@
|
||||
<color name="accentTransparent">#B0f9a825</color>
|
||||
<color name="separator">#eeeeee</color>
|
||||
<color name="bg_search">#fefefe</color>
|
||||
<color name="inverse">#a0000000</color>
|
||||
</resources>
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
<string name="format_two_names" translatable="false">%s, %s</string>
|
||||
<string name="format_two_parts" translatable="false">%s | %s</string>
|
||||
|
||||
|
||||
<integer name="terms_version_current">1</integer>
|
||||
<bool name="development_mode_default">false</bool>
|
||||
<bool name="privacy_measure_default">false</bool>
|
||||
@@ -36,6 +37,7 @@
|
||||
<bool name="show_pressure_default">true</bool>
|
||||
<bool name="show_humidity_default">true</bool>
|
||||
|
||||
<bool name="dark_mode">false</bool>
|
||||
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ allprojects {
|
||||
|
||||
// set version for our project
|
||||
group = 'com.mowesta'
|
||||
version = '1.0.4'
|
||||
version = '1.0.5'
|
||||
|
||||
// set versions for our libraries
|
||||
ext {
|
||||
|
||||
Reference in New Issue
Block a user