-
-
Notifications
You must be signed in to change notification settings - Fork 323
Add ParseListLoader #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
9e2b72a
2042424
a043d1d
fee83a7
6683d23
ee71557
82afd26
64a05bb
fa7ce83
5b801e3
c2931fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Create an App on [Parse.com](https://parse.com) then modify strings.xml with your keys | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Follow other samples' style <!-- Please put your application's app ID and keys here -->
<string name="parse_app_id">YOUR_PARSE_APP_ID</string>
<string name="parse_client_key">YOUR_PARSE_CLIENT_KEY</string> |
||
|
||
<string name="parse_app_id">YOUR_PARSE_APP_ID</string> | ||
<string name="parse_client_key">YOUR_PARSE_CLIENT_KEY</string> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion rootProject.ext.compileSdkVersion | ||
buildToolsVersion rootProject.ext.buildToolsVersion | ||
|
||
defaultConfig { | ||
applicationId "com.example.tuanchauict.parselistloaderexample" | ||
minSdkVersion rootProject.ext.minSdkVersion | ||
targetSdkVersion rootProject.ext.targetSdkVersion | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: we do not use proguardFiles for sample project. |
||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(include: ['*.jar'], dir: 'libs') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you use some local jar files? |
||
compile 'com.android.support:recyclerview-v7:21.+' | ||
compile project(':ParseLoginUI') | ||
compile rootProject.ext.androidSupport | ||
compile files(rootProject.ext.parsePath) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Please follow other samples' build.gradle |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: we do not use proguardFiles for sample project. |
||
# By default, the flags in this file are appended to flags specified | ||
# in /Users/tuanchauict/Data/Software/Dev/android-sdk-macosx/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.example.tuanchauict.parselistloaderexample; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Maybe delete this test? |
||
|
||
import android.app.Application; | ||
import android.test.ApplicationTestCase; | ||
|
||
/** | ||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a> | ||
*/ | ||
public class ApplicationTest extends ApplicationTestCase<Application> { | ||
public ApplicationTest() { | ||
super(Application.class); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest | ||
package="com.example.tuanchauict.parselistloaderexample" | ||
xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<uses-permission android:name="android.permission.INTERNET"/> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> | ||
<application | ||
android:allowBackup="true" | ||
android:icon="@drawable/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:name=".ListLoaderApplication" | ||
> | ||
<activity | ||
android:name=".MainActivity" | ||
android:label="@string/app_name" | ||
|
||
> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
|
||
<category android:name="android.intent.category.LAUNCHER"/> | ||
</intent-filter> | ||
</activity> | ||
|
||
<activity android:name=".listview.ListViewDemoActivity" android:label="List View"/> | ||
|
||
<activity android:name=".viewpager.ViewPagerDemoActivity" android:label="View Pager"/> | ||
|
||
<activity android:name=".recycler.RecyclerViewDemoActivity" android:label="Recycler View"/> | ||
|
||
<meta-data | ||
android:name="com.parse.APPLICATION_ID" | ||
android:value="@string/parse_app_id"/> | ||
<meta-data | ||
android:name="com.parse.CLIENT_KEY" | ||
android:value="@string/parse_client_key"/> | ||
</application> | ||
|
||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.example.tuanchauict.parselistloaderexample; | ||
|
||
import android.app.Application; | ||
|
||
import com.parse.Parse; | ||
import com.parse.ParseObject; | ||
|
||
/** | ||
* Created by tuanchauict on 10/25/15. | ||
*/ | ||
public class ListLoaderApplication extends Application { | ||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
|
||
// Required - Initialize the Parse SDK | ||
Parse.initialize(this); | ||
ParseObject.registerSubclass(ParseDemoObject.class); | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.example.tuanchauict.parselistloaderexample; | ||
|
||
import android.app.Activity; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.widget.Toast; | ||
|
||
import com.example.tuanchauict.parselistloaderexample.listview.ListViewDemoActivity; | ||
import com.example.tuanchauict.parselistloaderexample.recycler.RecyclerViewDemoActivity; | ||
import com.example.tuanchauict.parselistloaderexample.viewpager.ViewPagerDemoActivity; | ||
|
||
|
||
public class MainActivity extends Activity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
findViewById(R.id.create_1000_objects).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
create1000Objects(); | ||
} | ||
}); | ||
|
||
|
||
findViewById(R.id.goto_list_view).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
Intent intent = new Intent(MainActivity.this, ListViewDemoActivity.class); | ||
startActivity(intent); | ||
} | ||
}); | ||
|
||
findViewById(R.id.goto_viewpager).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
Intent intent = new Intent(MainActivity.this, ViewPagerDemoActivity.class); | ||
startActivity(intent); | ||
} | ||
}); | ||
|
||
findViewById(R.id.goto_recycler_view).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
Intent intent = new Intent(MainActivity.this, RecyclerViewDemoActivity.class); | ||
startActivity(intent); | ||
} | ||
}); | ||
} | ||
|
||
public void create1000Objects() { | ||
|
||
for (int i = 0; i < 1000; i++) { | ||
ParseDemoObject object = ParseDemoObject.getObject(i); | ||
object.saveEventually(); | ||
} | ||
Toast.makeText(this, "Check on your app's data", Toast.LENGTH_LONG).show(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.example.tuanchauict.parselistloaderexample; | ||
|
||
import com.parse.ParseClassName; | ||
import com.parse.ParseObject; | ||
|
||
/** | ||
* Created by tuanchauict on 10/25/15. | ||
*/ | ||
@ParseClassName("ListLoaderItem") | ||
public class ParseDemoObject extends ParseObject { | ||
public static final String ATTR_SSD = "ssd"; | ||
public static final String ATTR_FIRST_NAME = "firstName"; | ||
public static final String ATTR_LAST_NAME = "lastName"; | ||
|
||
|
||
public static ParseDemoObject getObject(int ssd){ | ||
ParseDemoObject object = new ParseDemoObject(); | ||
object.put(ATTR_SSD, ssd); | ||
object.put(ATTR_FIRST_NAME, "FirstName " + ssd); | ||
object.put(ATTR_LAST_NAME, "LastName " + ssd); | ||
return object; | ||
} | ||
|
||
|
||
public int getSSD(){ | ||
return getInt(ATTR_SSD); | ||
} | ||
|
||
public String getFirstname(){ | ||
return getString(ATTR_FIRST_NAME); | ||
} | ||
|
||
|
||
public String getLastName(){ | ||
return getString(ATTR_LAST_NAME); | ||
} | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.example.tuanchauict.parselistloaderexample.listview; | ||
|
||
import android.content.Context; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.ArrayAdapter; | ||
import android.widget.TextView; | ||
|
||
import com.example.tuanchauict.parselistloaderexample.ParseDemoObject; | ||
import com.example.tuanchauict.parselistloaderexample.R; | ||
import com.parse.ParseListLoader; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by tuanchauict on 10/25/15. | ||
*/ | ||
public class ListViewAdapter extends ArrayAdapter<ParseDemoObject> | ||
implements ParseListLoader.LoaderTarget<ParseDemoObject> { | ||
private List<ParseDemoObject> mObjects; | ||
private boolean mHasNextPage; | ||
|
||
private LayoutInflater mInflater; | ||
|
||
public ListViewAdapter(Context context) { | ||
super(context, 0); | ||
mInflater = LayoutInflater.from(context); | ||
mObjects = new ArrayList<>(); | ||
mHasNextPage = true; | ||
} | ||
|
||
public boolean hasNextPage() { | ||
return mHasNextPage; | ||
} | ||
|
||
public void setHasNextPage(boolean hasNextPage) { | ||
mHasNextPage = hasNextPage; | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
return mObjects.isEmpty() ? 0 : mHasNextPage ? mObjects.size() + 1 : mObjects.size(); | ||
} | ||
|
||
@Override | ||
public View getView(int position, View convertView, ViewGroup parent) { | ||
if(position >= mObjects.size()){ | ||
return mInflater.inflate(R.layout.item_waiting, parent, false); | ||
} | ||
|
||
if (convertView == null || convertView.getTag() != Boolean.TRUE) { | ||
convertView = mInflater.inflate(R.layout.item_layout, parent, false); | ||
convertView.setTag(Boolean.TRUE); | ||
} | ||
ParseDemoObject item = mObjects.get(position); | ||
|
||
((TextView) convertView.findViewById(R.id.txt_name)) | ||
.setText(item.getFirstname() + " " + item.getLastName()); | ||
|
||
return convertView; | ||
} | ||
|
||
@Override | ||
public void appendList(List<ParseDemoObject> sublist) { | ||
mObjects.addAll(sublist); | ||
} | ||
|
||
@Override | ||
public void clearList() { | ||
mObjects.clear(); | ||
} | ||
|
||
@Override | ||
public void notifyDataChanged() { | ||
notifyDataSetChanged(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use the root's gitignore?