mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-25 23:26:01 +00:00
"You aren't taking on any challenges at the moment" - View if no other challenges available
This commit is contained in:
parent
a281d7fbf8
commit
935eb4fe23
5 changed files with 121 additions and 26 deletions
|
|
@ -1,16 +1,82 @@
|
|||
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/challenges.refresh.layout"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/challenges.list"
|
||||
<android.support.v4.widget.SwipeRefreshLayout
|
||||
android:id="@+id/challenges.refresh.layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
android:divider="@null"
|
||||
android:scrollbars="vertical" />
|
||||
android:visibility="gone"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/challenges.list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
android:divider="@null"
|
||||
android:scrollbars="vertical" />
|
||||
|
||||
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
|
||||
<android.support.v4.widget.SwipeRefreshLayout
|
||||
android:id="@+id/challenges_refresh_empty"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||
|
||||
<android.support.v4.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/challenges.list.empty"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="48dp"
|
||||
android:layout_marginRight="48dp"
|
||||
android:layout_marginTop="65dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
style="@style/Headline"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:maxLines="2"
|
||||
android:text="@string/not_taking_any_challenges"
|
||||
android:textAlignment="center"
|
||||
android:textColor="#8a000000" />
|
||||
|
||||
<TextView
|
||||
style="@style/Body2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="22dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/join_a_challenge"
|
||||
android:textAlignment="center"
|
||||
android:textColor="#66000000" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView5"
|
||||
style="@style/Body2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="22dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/check_the_public_challenge_tab"
|
||||
android:textAlignment="center"
|
||||
android:textColor="#66000000" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</android.support.v4.widget.NestedScrollView>
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
</LinearLayout>
|
||||
|
|
@ -451,4 +451,7 @@ To start, which parts of your life do you want to improve?</string>
|
|||
<string name="participating">Participating</string>
|
||||
<string name="challenge">Challenge</string>
|
||||
<string name="go_to_challenge">Go to Challenge</string>
|
||||
<string name="not_taking_any_challenges">You aren\'t taking on any challenges at the moment</string>
|
||||
<string name="join_a_challenge">Join a Challenge to add its tasks to yours. Complete the tasks to win and you can get an achievement or even gems!</string>
|
||||
<string name="check_the_public_challenge_tab">Check the public Challenge tab to find ones you’d like to join.</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -75,4 +75,12 @@
|
|||
<item name="android:textSize">18sp</item>
|
||||
</style>
|
||||
|
||||
|
||||
<style name="Headline_Regular">
|
||||
<item name="android:fontFamily" tools:targetApi="jelly_bean">
|
||||
@string/font_family_regular
|
||||
</item>
|
||||
<item name="android:textSize">18sp</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
|
@ -166,6 +166,8 @@ public class ChallengeDetailActivity extends BaseActivity {
|
|||
challenge.async().save();
|
||||
|
||||
HabiticaApplication.User.resetChallengeList();
|
||||
finish();
|
||||
|
||||
}, throwable -> {
|
||||
});
|
||||
})
|
||||
|
|
|
|||
|
|
@ -26,13 +26,15 @@ import butterknife.BindView;
|
|||
import butterknife.ButterKnife;
|
||||
import rx.Observable;
|
||||
import rx.functions.Action0;
|
||||
import rx.functions.Action1;
|
||||
|
||||
public class ChallengeListFragment extends BaseMainFragment implements SwipeRefreshLayout.OnRefreshListener {
|
||||
|
||||
@BindView(R.id.challenges_refresh_layout)
|
||||
SwipeRefreshLayout swipeRefreshLayout;
|
||||
|
||||
@BindView(R.id.challenges_refresh_empty)
|
||||
SwipeRefreshLayout swipeRefreshEmptyLayout;
|
||||
|
||||
@BindView(R.id.challenges_list)
|
||||
RecyclerView recyclerView;
|
||||
|
||||
|
|
@ -51,11 +53,11 @@ public class ChallengeListFragment extends BaseMainFragment implements SwipeRefr
|
|||
this.viewUserChallengesOnly = only;
|
||||
}
|
||||
|
||||
public void setRefreshingCallback(Action0 refreshCallback){
|
||||
public void setRefreshingCallback(Action0 refreshCallback) {
|
||||
this.refreshCallback = refreshCallback;
|
||||
}
|
||||
|
||||
public void setObservable(Observable<ArrayList<Challenge>> listObservable){
|
||||
public void setObservable(Observable<ArrayList<Challenge>> listObservable) {
|
||||
listObservable
|
||||
.subscribe(challenges -> {
|
||||
|
||||
|
|
@ -79,20 +81,19 @@ public class ChallengeListFragment extends BaseMainFragment implements SwipeRefr
|
|||
}
|
||||
|
||||
if (viewUserChallengesOnly) {
|
||||
setAdapterEntries(userChallenges);
|
||||
setChallengeEntries(userChallenges);
|
||||
} else {
|
||||
setAdapterEntries(challenges);
|
||||
setChallengeEntries(challenges);
|
||||
}
|
||||
|
||||
if (swipeRefreshLayout != null) {
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
setRefreshingIfVisible(swipeRefreshLayout, false);
|
||||
setRefreshingIfVisible(swipeRefreshEmptyLayout, false);
|
||||
|
||||
}, throwable -> {
|
||||
Log.e("ChallengeListFragment", "", throwable);
|
||||
|
||||
if (swipeRefreshLayout != null) {
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
setRefreshingIfVisible(swipeRefreshLayout, false);
|
||||
setRefreshingIfVisible(swipeRefreshEmptyLayout, false);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -117,11 +118,18 @@ public class ChallengeListFragment extends BaseMainFragment implements SwipeRefr
|
|||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
swipeRefreshLayout.setRefreshing(true);
|
||||
setRefreshingIfVisible(swipeRefreshEmptyLayout, true);
|
||||
setRefreshingIfVisible(swipeRefreshLayout, true);
|
||||
|
||||
fetchOnlineChallenges();
|
||||
}
|
||||
|
||||
private void setRefreshingIfVisible(SwipeRefreshLayout refreshLayout, boolean state) {
|
||||
if (refreshLayout != null && refreshLayout.getVisibility() == View.VISIBLE) {
|
||||
refreshLayout.setRefreshing(state);
|
||||
}
|
||||
}
|
||||
|
||||
private void fetchLocalChallenges() {
|
||||
swipeRefreshLayout.setRefreshing(true);
|
||||
Where<Challenge> query = new Select().from(Challenge.class).where(Condition.column("name").isNotNull());
|
||||
|
|
@ -133,19 +141,27 @@ public class ChallengeListFragment extends BaseMainFragment implements SwipeRefr
|
|||
List<Challenge> challenges = query.queryList();
|
||||
|
||||
if (challenges.size() != 0) {
|
||||
setAdapterEntries(challenges);
|
||||
setChallengeEntries(challenges);
|
||||
}
|
||||
|
||||
// load online challenges & save to database
|
||||
onRefresh();
|
||||
}
|
||||
|
||||
private void fetchOnlineChallenges() {
|
||||
refreshCallback.call();
|
||||
private void setChallengeEntries(List<Challenge> challenges) {
|
||||
if (viewUserChallengesOnly && challenges.size() == 0) {
|
||||
swipeRefreshEmptyLayout.setVisibility(View.VISIBLE);
|
||||
swipeRefreshLayout.setVisibility(View.GONE);
|
||||
} else {
|
||||
swipeRefreshEmptyLayout.setVisibility(View.GONE);
|
||||
swipeRefreshLayout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
challengeAdapter.setChallenges(challenges);
|
||||
}
|
||||
|
||||
private void setAdapterEntries(List<Challenge> challenges) {
|
||||
challengeAdapter.setChallenges(challenges);
|
||||
private void fetchOnlineChallenges() {
|
||||
refreshCallback.call();
|
||||
}
|
||||
|
||||
public void addItem(Challenge challenge) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue