Skip to content

Commit

Permalink
Merge branch 'release/2.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
yukuku committed Mar 31, 2014
2 parents 3c7374e + 7351752 commit 4d08a75
Show file tree
Hide file tree
Showing 22 changed files with 4,222 additions and 59 deletions.
20 changes: 18 additions & 2 deletions android/LombaApp/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.thnkld.calegstore.app"
android:versionCode="9"
android:versionName="2.2.2">
android:versionCode="10"
android:versionName="2.3.0">
<uses-sdk android:minSdkVersion="14"
android:targetSdkVersion="18"/>
<uses-permission android:name="android.permission.INTERNET"/>
Expand All @@ -11,6 +11,12 @@
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>

<permission android:name="com.thnkld.calegstore.app.permission.C2D_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.thnkld.calegstore.app.permission.C2D_MESSAGE"/>

<application android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:theme="@style/Theme.Lomba"
Expand All @@ -30,5 +36,15 @@
</intent-filter>
</activity>
<activity android:name="lomba.app.ac.AboutActivity"/>

<receiver
android:name="lomba.app.gcm.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<category android:name="com.thnkld.calegstore.app"/>
</intent-filter>
</receiver>

</application>
</manifest>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions android/LombaApp/src/lomba/app/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import lomba.app.storage.Prefkey;
import yuku.afw.storage.Preferences;

import java.util.UUID;

public class App extends yuku.afw.App implements GooglePlayServicesClient.ConnectionCallbacks, GooglePlayServicesClient.OnConnectionFailedListener, LocationListener {
public static final String TAG = App.class.getSimpleName();

Expand Down Expand Up @@ -58,4 +60,13 @@ public void onLocationChanged(final Location loc) {
Preferences.setFloat(Prefkey.loc_lng, (float) lng);
}
}

public synchronized static String getInstallationId() {
String res = Preferences.getString(Prefkey.installation_id, null);
if (res == null) {
res = "u2:" + UUID.randomUUID().toString();
Preferences.setString(Prefkey.installation_id, res);
}
return res;
}
}
32 changes: 32 additions & 0 deletions android/LombaApp/src/lomba/app/U.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package lomba.app;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.net.Uri;
import android.text.TextUtils;
import lomba.app.storage.Prefkey;
Expand All @@ -11,6 +13,8 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class U {
public static final String TAG = U.class.getSimpleName();
Expand Down Expand Up @@ -107,4 +111,32 @@ public static String getNamaLembaga(final int lembaga) {
public static String getDapilDariLembaga(final int lembaga) {
return Preferences.getString(lembaga == 1? Prefkey.dapil_dpr: Prefkey.dapil_dprd1);
}

private static MessageDigest md5;

public static String md5(final String s) {
if (md5 == null) {
try {
md5 = MessageDigest.getInstance("md5");
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}

byte[] bb = md5.digest(s.trim().toLowerCase().getBytes());
StringBuilder sb = new StringBuilder();
for (byte b : bb) {
if (b >= 0 && b < 16) sb.append("0").append(Integer.toHexString(b));
else sb.append(Integer.toHexString(b & 0xff));
}
return sb.toString();
}

public static String getPrimaryAccountName() {
final Account[] accounts = AccountManager.get(App.context).getAccountsByType("com.google");
if (accounts != null) {
return accounts[0].name;
}
return null;
}
}
26 changes: 2 additions & 24 deletions android/LombaApp/src/lomba/app/ac/CalegActivity.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package lomba.app.ac;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.DialogFragment;
import android.app.Fragment;
import android.app.FragmentTransaction;
Expand Down Expand Up @@ -47,8 +45,6 @@
import yuku.afw.V;
import yuku.afw.widget.EasyAdapter;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
Expand All @@ -69,7 +65,6 @@ public class CalegActivity extends BaseActivity {
InfoAdapter adapter;
Papi.Caleg info;
private CommentAdapter commentsAdapter;
private MessageDigest md5;
private String accountName;
private PostCommentFragment postCommentFragment;
private ImageButton bP1;
Expand Down Expand Up @@ -111,10 +106,7 @@ protected void onCreate(final Bundle savedInstanceState) {
jazzy = V.get(this, R.id.jazzy);
jazzy.setAdapter(adapter = new InfoAdapter());
// jazzy.setTransitionEffect(JazzyViewPager.TransitionEffect.CubeIn);
final Account[] accounts = AccountManager.get(this).getAccountsByType("com.google");
if (accounts != null) {
accountName = accounts[0].name;
}
accountName = U.getPrimaryAccountName();

jazzy.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
Expand Down Expand Up @@ -572,21 +564,7 @@ private void displayRating() {
}

String grava(String email) {
if (md5 == null) {
try {
md5 = MessageDigest.getInstance("md5");
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}

byte[] bb = md5.digest(email.trim().toLowerCase().getBytes());
StringBuilder sb = new StringBuilder();
for (byte b : bb) {
if (b >= 0 && b < 16) sb.append("0").append(Integer.toHexString(b));
else sb.append(Integer.toHexString(b & 0xff));
}
String hasil = sb.toString();
String hasil = U.md5(email);

return "http://www.gravatar.com/avatar/" + hasil + "?s=80&d=identicon";
}
Expand Down
71 changes: 40 additions & 31 deletions android/LombaApp/src/lomba/app/ac/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.support.v4.widget.DrawerLayout;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
Expand All @@ -21,6 +22,7 @@
import android.widget.ListView;
import android.widget.PopupMenu;
import android.widget.TextView;
import com.google.android.gms.gcm.GoogleCloudMessaging;
import com.squareup.picasso.Picasso;
import com.thnkld.calegstore.app.R;
import lomba.app.App;
Expand All @@ -35,6 +37,7 @@
import yuku.afw.storage.Preferences;
import yuku.afw.widget.EasyAdapter;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
Expand All @@ -56,6 +59,7 @@ public class MainActivity extends BaseActivity {
Papi.Saklar partailoader;
Button cbDapilDpr;
Button cbDapilDprd1;
Papi.Saklar subscribeloader;

@Override
public void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -155,6 +159,40 @@ public boolean onMenuItemClick(final MenuItem item) {

setAbtitle(getString(R.string.app_name));
displayDrawerDapil();

sendGcmRegistration();
}

void sendGcmRegistration() {
final GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);

new Thread(new Runnable() {
@Override
public void run() {
try {
final String registration_id = gcm.register("928687239792");

final String dapil_dpr = Preferences.getString(Prefkey.dapil_dpr);
final String dapil_dprd1 = Preferences.getString(Prefkey.dapil_dprd1);

if (registration_id != null && dapil_dpr != null && dapil_dprd1 != null) {
subscribeloader = Papi.ganti(subscribeloader, Papi.subscribe(dapil_dpr + "," + dapil_dprd1, registration_id, App.getInstallationId(), new Papi.Clbk<Void>() {
@Override
public void success(final Void v) {

}

@Override
public void failed(final Throwable e) {

}
}));
}
} catch (IOException e) {
Log.e(TAG, "gagal register gcm", e);
}
}
}).start();
}

private void popupDapil(final Button button, final int lembaga) {
Expand All @@ -175,6 +213,7 @@ public boolean onMenuItemClick(final MenuItem item) {
Preferences.setString(lembaga == 1? Prefkey.dapil_dpr: Prefkey.dapil_dprd1, row.kode);
displayDrawerDapil();
LocalBroadcastManager.getInstance(App.context).sendBroadcast(new Intent(CALEG_BERUBAH));
sendGcmRegistration();
return true;
}
});
Expand All @@ -190,6 +229,7 @@ private void displayDrawerDapil() {
protected void onDestroy() {
super.onDestroy();
Papi.lupakan(partailoader);
Papi.lupakan(subscribeloader);
}

private void setLembaga(final int lembaga) {
Expand Down Expand Up @@ -330,35 +370,4 @@ public int getCount() {
return 1 + (partais == null? 0: partais.size());
}
}


class DapilAdapter extends EasyAdapter {
private final List<Dapil.Row> rows;

public DapilAdapter(final int lembaga) {
rows = Dapil.getRows(lembaga);
}

@Override
public View newView(final int position, final ViewGroup parent) {
return getLayoutInflater().inflate(android.R.layout.simple_spinner_item, parent, false);
}

@Override
public View newDropDownView(final int position, final ViewGroup parent) {
return getLayoutInflater().inflate(android.R.layout.simple_spinner_dropdown_item, parent, false);
}

@Override
public void bindView(final View view, final int position, final ViewGroup parent) {
TextView textView = (TextView) view;
final Dapil.Row row = rows.get(position);
textView.setText(row.desc);
}

@Override
public int getCount() {
return rows.size();
}
}
}
92 changes: 92 additions & 0 deletions android/LombaApp/src/lomba/app/gcm/GcmBroadcastReceiver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package lomba.app.gcm;

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.Target;
import com.thnkld.calegstore.app.R;
import lomba.app.U;
import lomba.app.ac.MainActivity;

public class GcmBroadcastReceiver extends BroadcastReceiver {
private static final String TAG = GcmBroadcastReceiver.class.getSimpleName();

public void onReceive(Context context, Intent intent) {
Log.d(TAG, "Got intent");
Log.d(TAG, " action: " + intent.getAction());
Log.d(TAG, " data uri: " + intent.getData());
Log.d(TAG, " component: " + intent.getComponent());
Log.d(TAG, " flags: 0x" + Integer.toHexString(intent.getFlags()));
Log.d(TAG, " mime: " + intent.getType());
Bundle extras = intent.getExtras();
Log.d(TAG, " extras: " + (extras == null? "null": extras.size()));
if (extras != null) {
for (String key: extras.keySet()) {
Log.d(TAG, " " + key + " = " + extras.get(key));
}
}

String title = intent.getStringExtra("title");
String content = intent.getStringExtra("content");
String kind = intent.getStringExtra("kind");
String caleg_name = intent.getStringExtra("caleg_name");
final String caleg_id = intent.getStringExtra("caleg_id");
String user_email = intent.getStringExtra("user_email");
String foto_url = intent.getStringExtra("foto_url");
String partai_nama = intent.getStringExtra("partai_nama");
String urutan = intent.getStringExtra("urutan");
float rating = Float.parseFloat(intent.getStringExtra("rating"));

if (user_email != null && !user_email.equals(U.getPrimaryAccountName())) {
if ("new_caleg_rating".equals(kind)) {
StringBuilder stars = new StringBuilder();
for (int i = 0; i < rating; i++) {
stars.append('\u2605');
}
for (int i = (int) rating; i < 5; i++) {
stars.append('\u2606');
}

final PendingIntent pi = PendingIntent.getActivity(context, 1, new Intent(context, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);

final NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_stat_notif)
.setContentTitle("[" + partai_nama + " no." + urutan + "] " + U.bagusinNama(caleg_name))
.setContentText(Html.fromHtml(stars + " <b>" + title + "</b> " + content))
.setTicker("Rating baru untuk " + U.bagusinNama(caleg_name))
.setContentIntent(pi)
.setAutoCancel(true);

final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

if (!TextUtils.isEmpty(foto_url)) {
Picasso.with(context).load(U.bc(144, 144, foto_url)).into(new Target() {
@Override
public void onBitmapLoaded(final Bitmap bitmap, final Picasso.LoadedFrom from) {
builder.setLargeIcon(bitmap);
nm.notify("new_caleg_rating:" + caleg_id, 1, builder.build());
}

@Override
public void onBitmapFailed(final Drawable errorDrawable) {
nm.notify("new_caleg_rating:" + caleg_id, 1, builder.build());
}

@Override
public void onPrepareLoad(final Drawable placeHolderDrawable) {}
});
}
}
}
}
}
Loading

0 comments on commit 4d08a75

Please sign in to comment.