Skip to content

Commit

Permalink
修正 LBSActivity 只有第一次自動執行查詢的問題
Browse files Browse the repository at this point in the history
  • Loading branch information
ccjeng committed Sep 25, 2016
1 parent 68a4d17 commit d25c2dc
Show file tree
Hide file tree
Showing 11 changed files with 405 additions and 415 deletions.
568 changes: 296 additions & 272 deletions .idea/workspace.xml

Large diffs are not rendered by default.

20 changes: 11 additions & 9 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
Expand All @@ -83,6 +75,14 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
Expand Down Expand Up @@ -119,6 +119,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.firebase/firebase-analytics/9.6.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.firebase/firebase-common/9.6.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.firebase/firebase-core/9.6.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.firebase/firebase-crash/9.6.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.firebase/firebase-iid/9.6.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.mikepenz/aboutlibraries/5.7.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.mikepenz/community-material-typeface/1.3.41.1/jars" />
Expand Down Expand Up @@ -189,8 +190,8 @@
<orderEntry type="library" exported="" name="retrofit-2.1.0" level="project" />
<orderEntry type="library" exported="" name="gson-2.7" level="project" />
<orderEntry type="library" exported="" name="converter-gson-2.1.0" level="project" />
<orderEntry type="library" exported="" name="avoscloud-sdk-v3.14.4" level="project" />
<orderEntry type="library" exported="" name="rxandroid-1.2.1" level="project" />
<orderEntry type="library" exported="" name="avoscloud-sdk-v3.14.3" level="project" />
<orderEntry type="library" exported="" name="aboutlibraries-5.7.1" level="project" />
<orderEntry type="library" exported="" name="play-services-basement-9.6.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-24.2.1" level="project" />
Expand All @@ -200,5 +201,6 @@
<orderEntry type="library" exported="" name="logging-interceptor-3.4.1" level="project" />
<orderEntry type="library" exported="" name="firebase-analytics-9.6.1" level="project" />
<orderEntry type="library" exported="" name="admob-adapter-1.0.0-1505261651-830485e" level="project" />
<orderEntry type="library" exported="" name="firebase-crash-9.6.1" level="project" />
</component>
</module>
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId 'com.oddsoft.tpetrash2'
minSdkVersion 16
targetSdkVersion 21
versionCode 56
versionName '4.2.3.082716TT'
versionCode 57
versionName '4.3.0.092516TT'
multiDexEnabled true
}
buildTypes {
Expand Down Expand Up @@ -53,15 +53,15 @@ dependencies {
compile 'com.google.android.gms:play-services-location:9.6.1'
compile 'com.google.firebase:firebase-core:9.6.1'
compile 'com.google.firebase:firebase-ads:9.6.1'
// compile 'com.google.firebase:firebase-crash:9.6.1'
compile 'com.google.firebase:firebase-crash:9.6.1'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.mikepenz:iconics-core:2.7.1@aar'
compile 'com.mikepenz:fontawesome-typeface:4.5.0.1@aar'
compile 'com.mikepenz:community-material-typeface:1.3.41.1@aar'
compile 'com.pnikosis:materialish-progress:1.7'
compile 'cn.leancloud.android:avoscloud-sdk:v3.14.3'
compile 'cn.leancloud.android:avoscloud-sdk:v3.14.4'
compile 'io.reactivex:rxjava:1.2.0'
compile 'io.reactivex:rxandroid:1.2.1'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class LBSPresenter extends BasePresenter<LBSView> implements LocationConn
private LBSView view;
private Context context;
private LocationService locationService;
private Location currentLocation;
public Location currentLocation;

public int distance;
public String sorting;
Expand All @@ -49,9 +49,6 @@ public void runQuery(final int day, final int hour, final String sort) {

if (currentLocation != null) {

//set current location to global veriable
Application.setCurrentLocation(currentLocation);

if (Application.APPDEBUG)
Log.d(TAG, "location = " + currentLocation.toString());

Expand All @@ -77,6 +74,7 @@ public void done(List<ArrayItem> avObjects, AVException e) {

if (e == null) {
view.setRecyclerView(avObjects, currentLocation);
// Application.setRefreshFlag(true);

} else {
view.showError(context.getString(R.string.network_error), Utils.Mode.ERROR);
Expand Down Expand Up @@ -122,8 +120,8 @@ public void onCreate() {
}
}

/*
LocationConnectedListener
/**
* LocationConnectedListener
* */
@Override
public void onLocationServiceConnected(Location location) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ public void initView() {
hour = 5;
}

//set today's day by default
daySpinner.setSelection(Arrays.asList(dayCode).indexOf(String.valueOf(today)));

if (mPresenter.currentLocation != null) {
hourSpinner.setSelection(Arrays.asList(hourCode).indexOf(String.valueOf(hour)));
}

adView();
}

Expand Down Expand Up @@ -218,12 +225,25 @@ public void spinnerSelected() {

}

/**
* Run first time when activity launch, trigger by LocationService.onConnected
* **/
@Override
public void spinnerSetSelection() {
if (Application.getRefreshFlag()) {
daySpinner.setSelection(Arrays.asList(dayCode).indexOf(String.valueOf(today)));
hourSpinner.setSelection(Arrays.asList(hourCode).indexOf(String.valueOf(hour)));
Application.setRefreshFlag(false);

int newPositionValue = Arrays.asList(hourCode).indexOf(String.valueOf(hour));
int currentPosition = hourSpinner.getSelectedItemPosition();

Log.d(TAG, "hourSpinner.getSelectedItemPosition() = " + currentPosition);
/*
if (!currentPosition.equals(newPositionValue)) {
Log.d(TAG, "!currentPosition.equals(newPositionValue)");
// do noting (do not refresh when infoactivy back to lbsactivity)
}*/
if (currentPosition == 0) {
Log.d(TAG, "currentPosition == 0");
// only run the first time when activity launch
hourSpinner.setSelection(newPositionValue);
}
}

Expand All @@ -245,8 +265,6 @@ public void onItemClick(ArrayItem item) {
if (items.size() == 0) {
this.showError(getString(R.string.data_not_found), Utils.Mode.INFO);
}


}

private void adView() {
Expand Down Expand Up @@ -337,7 +355,6 @@ protected void onDestroy() {
super.onDestroy();
}


private void goIntent(ArrayItem item, Location location) {

ga.trackEvent(this, "Location", "Region", item.getRegion(), 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,31 @@
* Created by andycheng on 2015/5/5.
*/

import android.location.Location;

import com.avos.avoscloud.AVOSCloud;
import com.avos.avoscloud.AVObject;
import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Logger;
import com.google.android.gms.analytics.Tracker;
import com.oddsoft.tpetrash2.BuildConfig;
import com.oddsoft.tpetrash2.R;
import com.oddsoft.tpetrash2.view.adapter.ArrayItem;
import com.oddsoft.tpetrash2.utils.Constant;
import com.oddsoft.tpetrash2.view.adapter.ArrayItem;

import java.util.HashMap;


public class Application extends android.app.Application {
// Debugging switch 
public static final boolean APPDEBUG = BuildConfig.DEBUG;

// Debugging tag for the application
public static final String APPTAG = Application.class.getSimpleName();

public Application() {
}

@Override
public void onCreate() {
super.onCreate();

AVOSCloud.initialize(this, Constant.LEANCLOUD_APP_ID, Constant.LEANCLOUD_APP_KEY);
AVOSCloud.useAVCloudCN();
AVObject.registerSubclass(ArrayItem.class);

}


// The following line should be changed to include the correct property id.
private static final String PROPERTY_ID = "UA-19743390-13";
public enum TrackerName {
Expand All @@ -63,25 +52,4 @@ public synchronized Tracker getTracker(TrackerName trackerId) {
return mTrackers.get(trackerId);
}

//Global variable for current location
private static Location mLocation;
public static Location getCurrentLocation(){
if (mLocation == null) {
mLocation = new Location("");
mLocation.setLatitude(24.8979347);
mLocation.setLongitude(121.5393508);
}
return mLocation;
}
public static void setCurrentLocation(Location l){
mLocation = l;
}

private static Boolean mRefresh = true;
public static Boolean getRefreshFlag(){
return mRefresh;
}
public static void setRefreshFlag(Boolean s){
mRefresh = s;
}
}
1 change: 0 additions & 1 deletion app/src/main/res/layout/activity_lbs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
</android.support.design.widget.AppBarLayout>



<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
Expand Down
14 changes: 1 addition & 13 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:wheel="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
Expand All @@ -23,21 +22,10 @@
android:background="@color/write"
tools:context=".view.activity.MainActivity">

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

</LinearLayout>
android:layout_height="wrap_content" />

<android.support.design.widget.NavigationView
android:id="@+id/navigation"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/layout_item_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
android:focusable="true"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
android:layout_margin="1dp"
android:layout_margin="5dp"
card_view:cardCornerRadius="8dp"
card_view:cardElevation="6dp">

Expand Down
Loading

0 comments on commit d25c2dc

Please sign in to comment.