Skip to content

Commit

Permalink
2.705
Browse files Browse the repository at this point in the history
  • Loading branch information
WangDaYeeeeee committed Jan 28, 2021
1 parent fb90405 commit fa0aa62
Show file tree
Hide file tree
Showing 32 changed files with 109,983 additions and 106,276 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "wangdaye.com.geometricweather"
minSdkVersion 19
targetSdkVersion 30
versionCode 27003
versionName "2.703"
versionCode 27005
versionName "2.705"
multiDexEnabled true
ndk {
abiFilters 'armeabi', 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a'
Expand Down
6 changes: 3 additions & 3 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
{
"type": "SINGLE",
"filters": [],
"versionCode": 27003,
"versionName": "2.703",
"outputFile": "GeometricWeather 2.703.apk"
"versionCode": 27005,
"versionName": "2.705",
"outputFile": "GeometricWeather 2.705.apk"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public void onRequestPermissionsResult(int requestCode,
super.onRequestPermissionsResult(requestCode, permission, grantResult);
if (permissionsListener != null) {
permissionsListener.onRequestPermissionsResult(requestCode, permission, grantResult);
permissionsListener = null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ public void onLocationListChanged() {

// control.

@SuppressLint("SetTextI18n")
@SuppressLint({"SetTextI18n", "ClickableViewAccessibility"})
private void drawUI(Location location, boolean defaultLocation, LocationResource.Source source) {
if (location.equals(currentLocationFormattedId)
&& location.getWeatherSource() == currentWeatherSource
Expand All @@ -411,7 +411,18 @@ private void drawUI(Location location, boolean defaultLocation, LocationResource

if (location.getWeather() == null) {
resetUI(location);

binding.recyclerView.setOnTouchListener((v, event) -> {
if (event.getAction() == MotionEvent.ACTION_DOWN
&& !binding.refreshLayout.isRefreshing()) {
viewModel.updateWeather(this, true);
}
return false;
});

return;
} else {
binding.recyclerView.setOnTouchListener(null);
}

if (needToResetUI) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public Location getLocationFromList(int offset) {
return validList.get((validIndex + offset + validList.size()) % validList.size());
}

public void updateWeather(GeoActivity activity, boolean swipeToRefresh) {
public void updateWeather(GeoActivity activity, boolean triggeredByUser) {
if (currentLocation.getValue() == null) {
return;
}
Expand All @@ -204,58 +204,65 @@ public void updateWeather(GeoActivity activity, boolean swipeToRefresh) {
)
);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && location.isCurrentPosition()) {
// check basic location permissions.
List<String> permissionList = getDeniedPermissionList(activity, false);
if (permissionList.size() != 0) {
// request basic location permissions.
activity.requestPermissions(permissionList.toArray(new String[0]), 0,
(requestCode, permission, grantResult) -> {
for (int i = 0; i < permission.length && i < grantResult.length; i++) {
if (isPivotalPermission(permission[i])
&& grantResult[i] != PackageManager.PERMISSION_GRANTED) {
// denied basic location permissions.
if (location.isUsable()) {
repository.getWeather(
activity, location, false, swipeToRefresh, this);
} else {
currentLocation.setValue(
LocationResource.error(
location,
true,
LocationResource.Source.REFRESH
)
);
}
return;
}
}

// check background location permissions.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
List<String> backgroundPermissionList = getDeniedPermissionList(activity, true);
if (backgroundPermissionList.size() != 0) {
BackgroundLocationDialog dialog = new BackgroundLocationDialog();
dialog.setOnSetButtonClickListener(() ->
activity.requestPermissions(
backgroundPermissionList.toArray(new String[0]),
0,
null
)
);
dialog.show(activity.getSupportFragmentManager(), null);
}
}

repository.getWeather(
activity, location, true, swipeToRefresh, this);
});
return;
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || !location.isCurrentPosition()) {
// don't need to request any permission -> request data directly.
repository.getWeather(
activity, location, location.isCurrentPosition(), triggeredByUser, this);
return;
}

repository.getWeather(
activity, location, location.isCurrentPosition(), swipeToRefresh, this);
// check basic location permissions.
List<String> permissionList = getDeniedPermissionList(activity, false);
if (permissionList.size() == 0) {
// already got all permissions -> request data directly.
repository.getWeather(
activity, location, true, triggeredByUser, this);
return;
}

// need request permissions -> request basic location permissions.
String[] permissions = permissionList.toArray(new String[0]);
activity.requestPermissions(permissions, 0, (requestCode, permission, grantResult) -> {

for (int i = 0; i < permission.length && i < grantResult.length; i++) {
if (isPivotalPermission(permission[i])
&& grantResult[i] != PackageManager.PERMISSION_GRANTED) {
// denied basic location permissions.
if (location.isUsable()) {
repository.getWeather(
activity, location, false, triggeredByUser, this);
} else {
currentLocation.setValue(
LocationResource.error(
location,
true,
LocationResource.Source.REFRESH
)
);
}
return;
}
}

// check background location permissions.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
List<String> backgroundPermissionList = getDeniedPermissionList(activity, true);
if (backgroundPermissionList.size() != 0) {
BackgroundLocationDialog dialog = new BackgroundLocationDialog();
dialog.setOnSetButtonClickListener(() ->
activity.requestPermissions(
backgroundPermissionList.toArray(new String[0]),
0,
null
)
);
dialog.show(activity.getSupportFragmentManager(), null);
}
}

repository.getWeather(
activity, location, true, triggeredByUser, this);
});
}

private List<String> getDeniedPermissionList(Context context, boolean background) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ private void initView() {
insets, false, true, drawerMode, false).setPaddingRelative(v));

viewModel.getListResource().observe(getViewLifecycleOwner(), resource -> {

if (adapter == null) {
adapter = new LocationAdapter(
requireActivity(),
Expand All @@ -121,7 +122,7 @@ private void initView() {
} else if (resource.source instanceof SelectableLocationListResource.ItemMoved) {
SelectableLocationListResource.ItemMoved source
= (SelectableLocationListResource.ItemMoved) resource.source;
adapter.notifyItemMoved(source.from, source.to);
adapter.update(source.from, source.to);
} else {
adapter.update(resource.dataList, resource.selectedId, resource.forceUpdateId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void init(Context context, @Nullable String selectedId) {
}

public void readAppendCache(Context context) {
List<Location> oldList = Collections.unmodifiableList(getLocationList());
List<Location> oldList = getLocationList();
repository.readAppendLocation(context, oldList, locationList -> {
if (locationList == null) {
return;
Expand All @@ -57,20 +57,20 @@ public void readAppendCache(Context context) {
}

public void addLocation(Context context, Location location) {
addLocation(context, location, getLocationList().size());
addLocation(context, location, getLocationCount());
}

public void addLocation(Context context, Location location, int position) {
List<Location> list = getLocationList();
List<Location> list = innerGetLocationList();
list.add(position, location);

listResource.setValue(
new SelectableLocationListResource(list, getSelectedId(), null));

if (position == getLocationList().size() - 1) {
if (position == getLocationCount() - 1) {
repository.writeLocation(context, location);
} else {
repository.writeLocationList(context, list, position);
repository.writeLocationList(context, Collections.unmodifiableList(list), position);
}
}

Expand Down Expand Up @@ -118,10 +118,11 @@ public void updateLocation(Context context,
}

public void moveLocation(int from, int to) {
Collections.swap(getLocationList(), from, to);
List<Location> list = innerGetLocationList();
Collections.swap(list, from, to);
listResource.setValue(
new SelectableLocationListResource(
getLocationList(),
list,
getSelectedId(),
null,
new SelectableLocationListResource.ItemMoved(from, to)
Expand All @@ -134,7 +135,7 @@ public void moveLocationFinish(Context context) {
}

public void forceUpdateLocation(Context context, Location location, int position) {
List<Location> list = getLocationList();
List<Location> list = innerGetLocationList();
list.set(position, location);

listResource.setValue(
Expand All @@ -149,7 +150,7 @@ public void forceUpdateLocation(Context context, Location location, int position
}

public Location deleteLocation(Context context, int position) {
List<Location> list = getLocationList();
List<Location> list = innerGetLocationList();
Location location = list.remove(position);

location.setWeather(DatabaseHelper.getInstance(context).readWeather(location));
Expand All @@ -166,15 +167,27 @@ public Location deleteLocation(Context context, int position) {
return location;
}

private List<Location> innerGetLocationList() {
if (listResource.getValue() == null) {
return new ArrayList<>();
}
return listResource.getValue().dataList;
}

public MutableLiveData<SelectableLocationListResource> getListResource() {
return listResource;
}

public List<Location> getLocationList() {
if (listResource.getValue() == null) {
return new ArrayList<>();
}
return listResource.getValue().dataList;
return Collections.unmodifiableList(innerGetLocationList());
}

public Location getLocation(int position) {
return innerGetLocationList().get(position);
}

public int getLocationCount() {
return innerGetLocationList().size();
}

public String getSelectedId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.ListAdapter;

import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -24,13 +23,14 @@
import wangdaye.com.geometricweather.resource.provider.ResourceProvider;
import wangdaye.com.geometricweather.resource.provider.ResourcesProviderFactory;
import wangdaye.com.geometricweather.settings.SettingsOptionManager;
import wangdaye.com.geometricweather.ui.adapter.SyncListAdapter;
import wangdaye.com.geometricweather.utils.manager.ThemeManager;

/**
* Location adapter.
* */

public class LocationAdapter extends ListAdapter<LocationModel, LocationHolder>
public class LocationAdapter extends SyncListAdapter<LocationModel, LocationHolder>
implements ICustomAdapter {

private final Context context;
Expand All @@ -46,7 +46,7 @@ public LocationAdapter(Context context,
@Nullable String selectedId,
@NonNull OnLocationItemClickListener clickListener,
@Nullable OnLocationItemDragListener dragListener) {
super(new DiffUtil.ItemCallback<LocationModel>() {
super(new ArrayList<>(), new DiffUtil.ItemCallback<LocationModel>() {
@Override
public boolean areItemsTheSame(@NonNull LocationModel oldItem, @NonNull LocationModel newItem) {
return oldItem.areItemsTheSame(newItem);
Expand Down Expand Up @@ -119,6 +119,15 @@ public void update(@NonNull List<Location> newList,
submitList(modelList);
}

public void update(int from, int to) {
submitMove(from, to);
}

@Override
public void submitList(@NonNull List<LocationModel> newList) {
super.submitList(newList);
}

@ColorInt
public int getItemSourceColor(int position) {
if (0 <= position && position < getItemCount()) {
Expand Down
Loading

0 comments on commit fa0aa62

Please sign in to comment.