Skip to content

Commit

Permalink
fixed db delete bug
Browse files Browse the repository at this point in the history
  • Loading branch information
agenthun committed Dec 7, 2015
1 parent e70a704 commit 1447fd1
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.EditText;
import android.widget.Toast;

import com.agenthun.readingroutine.R;
import com.agenthun.readingroutine.datastore.UserData;
import com.agenthun.readingroutine.transitionmanagers.TActivity;
import com.daimajia.androidanimations.library.Techniques;
import com.daimajia.androidanimations.library.YoYo;

Expand All @@ -22,7 +22,7 @@
/**
* A login screen that offers login via email/password.
*/
public class LoginActivity extends AppCompatActivity {
public class LoginActivity extends TActivity {

private static final String TAG = "LoginActivity";

Expand Down Expand Up @@ -51,9 +51,15 @@ protected void onCreate(Bundle savedInstanceState) {
finish();
} else {
userData = new UserData();
setIsTrial(true);
}
}

@Override
protected int getFragmentContainerId() {
return 0;
}

@Override
public void onBackPressed() {
finish();
Expand All @@ -70,7 +76,10 @@ public void onSignInBtnClick() {

@OnClick(R.id.trial_button)
public void onTrialBtnClick() {
Log.d(TAG, "onTrialBtnClick() returned: ");
setIsTrial(true);
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
finish();
}

@OnClick(R.id.forget_password_button)
Expand Down Expand Up @@ -115,6 +124,7 @@ private void attemptLogin() {
userData.login(LoginActivity.this, new SaveListener() {
@Override
public void onSuccess() {
setIsTrial(false);
Toast.makeText(LoginActivity.this, R.string.msg_success, Toast.LENGTH_SHORT).show();
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,16 @@ public void onError(int i, String s) {
} else {
Picasso.with(this).load((File) UserData.getObjectByKey(this, "pic")).transform(new CircleTransformation()).into(avator);
}*/
final CircleTransformation transformation = new CircleTransformation(this, 2);
transformation.setBorderColor(getResources().getColor(R.color.gray_200));
/* Bitmap bitmap = BitmapFactory.decodeResource(getResources(), Avatar.values()[((int) UserData.getObjectByKey(this, "avatarId"))].getDrawableId());
Palette palette = Palette.from(bitmap).generate();
Palette.Swatch swatch = palette.getVibrantSwatch();
transformation.setBorderColor(palette.getMutedColor(Color.WHITE));*/
if (!getIsTrial()) {
final CircleTransformation transformation = new CircleTransformation(this, 2);
// transformation.setBorderColor(getResources().getColor(R.color.gray_200));

Picasso.with(this).load(Avatar.values()[((int) UserData.getObjectByKey(this, "avatarId"))].getDrawableId())
.transform(transformation).into(avator);

name.setText((String) UserData.getObjectByKey(this, "username"));
email.setText((String) UserData.getObjectByKey(this, "email"));
Picasso.with(this).load(Avatar.values()[((int) UserData.getObjectByKey(this, "avatarId"))].getDrawableId())
.transform(transformation).into(avator);

name.setText((String) UserData.getObjectByKey(this, "username"));
email.setText((String) UserData.getObjectByKey(this, "email"));
}
materialMenuIconToolbar = new MaterialMenuIconToolbar(this, getResources().getColor(R.color.color_white), MaterialMenuDrawable.Stroke.REGULAR) {
@Override
public int getToolbarViewId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.design.widget.Snackbar;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
Expand All @@ -15,10 +15,13 @@
import com.agenthun.readingroutine.R;
import com.agenthun.readingroutine.adapters.AvatarAdapter;
import com.agenthun.readingroutine.datastore.UserData;
import com.agenthun.readingroutine.transitionmanagers.TActivity;
import com.agenthun.readingroutine.utils.Avatar;
import com.agenthun.readingroutine.utils.UiUtils;
import com.balysv.materialmenu.MaterialMenuDrawable;
import com.balysv.materialmenu.extras.toolbar.MaterialMenuIconToolbar;
import com.daimajia.androidanimations.library.Techniques;
import com.daimajia.androidanimations.library.YoYo;

import cn.bmob.v3.BmobUser;
import cn.bmob.v3.listener.EmailVerifyListener;
Expand All @@ -29,7 +32,7 @@
* @authors agenthun
* @date 15/12/6 上午12:41.
*/
public class SignUpGridActivity extends AppCompatActivity {
public class SignUpGridActivity extends TActivity {

private static final String TAG = "SignUpGridActivity";

Expand Down Expand Up @@ -136,6 +139,11 @@ private void attemptSignUpAndLogin() {
String signUpPassword = passwpord.getText().toString();
String signUpPasswordAgain = passwpordAgain.getText().toString();

if (!signUpPassword.equals(signUpPasswordAgain)) {
Snackbar.make(avatarGrid, R.string.error_difference_password, Snackbar.LENGTH_SHORT).show();
YoYo.with(Techniques.Shake).duration(500).delay(100).playOn(passwpordAgain);
return;
}
final UserData newUser = new UserData();
newUser.setUsername(signUpName);
newUser.setPassword(signUpPassword);
Expand All @@ -145,6 +153,7 @@ private void attemptSignUpAndLogin() {
@Override
public void onSuccess() {
//Toast.makeText(SignUpActivity.this, R.string.success_sign_up, Toast.LENGTH_SHORT).show();
setIsTrial(false);
Intent intent = new Intent(SignUpGridActivity.this, MainActivity.class);
startActivity(intent);

Expand All @@ -170,6 +179,11 @@ public void onFailure(int i, String s) {
});
}

@Override
protected int getFragmentContainerId() {
return 0;
}

@Override
public void onBackPressed() {
super.onBackPressed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,17 @@
import android.support.v7.app.AppCompatActivity;

import com.agenthun.readingroutine.R;
import com.agenthun.readingroutine.fragments.SettingsFragment;

/**
* Created by Agent Henry on 2015/7/25.
*/
public class SplashActivity extends AppCompatActivity {

private static final String IS_FIRST = "IS_FIRST";

private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
Intent intent = new Intent(Intent.ACTION_MAIN);
if (getIsFirst()) {
intent.setClass(getApplicationContext(), LoginActivity.class);
} else {
intent.setClass(getApplicationContext(), LoginActivity.class);
}
intent.setClass(getApplicationContext(), LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
Expand All @@ -37,14 +30,4 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_splash);
handler.sendEmptyMessageDelayed(0, 1500);
}

public void setIsFirst(boolean isFirst) {
getApplicationContext().getSharedPreferences(SettingsFragment.GLOBAL_SETTINGS, 0)
.edit().putBoolean(IS_FIRST, isFirst);
}

public boolean getIsFirst() {
return getApplicationContext().getSharedPreferences(SettingsFragment.GLOBAL_SETTINGS, 0)
.getBoolean(IS_FIRST, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public void deleteBookInfo(BookInfo bookInfo) {
}
if (cursor == null) {
where = BookDBHelper.BookinfoTable.USER_ID + " = '" + LoginActivity.userData.getObjectId()
+ "' AND " + BookDBHelper.BookinfoTable.BOOK_NAME + " = '" + bookInfo.getBookName() + "'"
+ "' AND " + BookDBHelper.BookinfoTable.BOOK_COLOR + " = '" + bookInfo.getBookColor() + "'"
+ "' AND " + BookDBHelper.BookinfoTable.BOOK_NAME + " = '" + bookInfo.getBookName()
+ "' AND " + BookDBHelper.BookinfoTable.BOOK_COLOR + " = '" + bookInfo.getBookColor()
+ "' AND " + BookDBHelper.BookinfoTable.BOOK_ALARM_TIME + " = '" + bookInfo.getBookAlarmTime() + "'";
cursor = bookDBHelper.query(BookDBHelper.TABLE_NAME, null, where, null, null, null, null);
if (cursor != null && cursor.getCount() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.util.Log;

import com.agenthun.readingroutine.activities.LoginActivity;
import com.agenthun.readingroutine.datastore.BookInfo;
import com.agenthun.readingroutine.datastore.NoteInfo;

import java.util.ArrayList;
Expand Down Expand Up @@ -61,9 +60,9 @@ public void deleteNote(NoteInfo noteInfo) {
}
if (cursor == null) {
where = NoteDBHelper.NoteTable.USER_ID + " = '" + LoginActivity.userData.getObjectId()
+ "' AND " + NoteDBHelper.NoteTable.NOTE_TITLE + " = '" + noteInfo.getNoteTitle() + "'"
+ "' AND " + NoteDBHelper.NoteTable.NOTE_COMPOSE + " = '" + noteInfo.getNoteCompose() + "'"
+ "' AND " + NoteDBHelper.NoteTable.NOTE_CREATE_TIME + " = '" + noteInfo.getNoteCreateTime() + "'"
+ "' AND " + NoteDBHelper.NoteTable.NOTE_TITLE + " = '" + noteInfo.getNoteTitle()
+ "' AND " + NoteDBHelper.NoteTable.NOTE_COMPOSE + " = '" + noteInfo.getNoteCompose()
+ "' AND " + NoteDBHelper.NoteTable.NOTE_CREATE_TIME + " = '" + noteInfo.getNoteCreateTime()
+ "' AND " + NoteDBHelper.NoteTable.NOTE_COLOR + " = '" + noteInfo.getNoteColor() + "'";
cursor = noteDBHelper.query(NoteDBHelper.TABLE_NAME, null, where, null, null, null, null);
if (cursor != null && cursor.getCount() > 0) {
Expand All @@ -81,9 +80,9 @@ public void deleteNote(NoteInfo noteInfo) {
public void deleteNote(NoteInfo noteInfo, boolean isOffline) {
Cursor cursor = null;
String where = NoteDBHelper.NoteTable.USER_ID + " = '" + LoginActivity.userData.getObjectId()
+ "' AND " + NoteDBHelper.NoteTable.NOTE_TITLE + " = '" + noteInfo.getNoteTitle() + "'"
+ "' AND " + NoteDBHelper.NoteTable.NOTE_COMPOSE + " = '" + noteInfo.getNoteCompose() + "'"
+ "' AND " + NoteDBHelper.NoteTable.NOTE_CREATE_TIME + " = '" + noteInfo.getNoteCreateTime() + "'"
+ "' AND " + NoteDBHelper.NoteTable.NOTE_TITLE + " = '" + noteInfo.getNoteTitle()
+ "' AND " + NoteDBHelper.NoteTable.NOTE_COMPOSE + " = '" + noteInfo.getNoteCompose()
+ "' AND " + NoteDBHelper.NoteTable.NOTE_CREATE_TIME + " = '" + noteInfo.getNoteCreateTime()
+ "' AND " + NoteDBHelper.NoteTable.NOTE_COLOR + " = '" + noteInfo.getNoteColor() + "'";
cursor = noteDBHelper.query(NoteDBHelper.TABLE_NAME, null, where, null, null, null, null);
if (cursor != null && cursor.getCount() > 0) {
Expand Down Expand Up @@ -141,7 +140,7 @@ public long insertNote(NoteInfo noteInfo, NoteInfo noteInfoOld, boolean isOfflin
if (cursor != null && cursor.getCount() > 0) {
cursor.moveToFirst();
ContentValues contentValues = new ContentValues();
contentValues.put(NoteDBHelper.NoteTable.USER_ID, LoginActivity.userData.getObjectId());
contentValues.put(NoteDBHelper.NoteTable.USER_ID, "null");
contentValues.put(NoteDBHelper.NoteTable.OBJECT_ID, noteInfo.getObjectId());
contentValues.put(NoteDBHelper.NoteTable.NOTE_TITLE, noteInfo.getNoteTitle());
contentValues.put(NoteDBHelper.NoteTable.NOTE_COMPOSE, noteInfo.getNoteCompose());
Expand All @@ -151,7 +150,7 @@ public long insertNote(NoteInfo noteInfo, NoteInfo noteInfoOld, boolean isOfflin
Log.i(TAG, "update");
} else {
ContentValues contentValues = new ContentValues();
contentValues.put(NoteDBHelper.NoteTable.USER_ID, LoginActivity.userData.getObjectId());
contentValues.put(NoteDBHelper.NoteTable.USER_ID, "null");
contentValues.put(NoteDBHelper.NoteTable.OBJECT_ID, noteInfo.getObjectId());
contentValues.put(NoteDBHelper.NoteTable.NOTE_TITLE, noteInfo.getNoteTitle());
contentValues.put(NoteDBHelper.NoteTable.NOTE_COMPOSE, noteInfo.getNoteCompose());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
private void setupDatabase() {
databaseUtil = NoteDatabaseUtil.getInstance(getContext());
mDataSet = databaseUtil.queryNoteInfos();
if (mDataSet == null) {
if (mDataSet == null && getIsTrial() != true) {
BmobQuery<NoteInfo> bmobQuery = new BmobQuery<>();
bmobQuery.setLimit(10);

Expand Down Expand Up @@ -323,6 +323,9 @@ public void onFailure(int i, String s) {
databaseUtil.deleteNote(noteInfo, true);
}
});
if (getIsTrial()) {
databaseUtil.deleteNote(noteInfo, true);
}

int size = mDataSet.size();
if (size > 0 && position < size) {
Expand All @@ -346,6 +349,7 @@ private void updateItem(final int position, String title, String compose, String
noteInfo.setNoteColor(colorIndex);

Log.i(TAG, "test id = " + noteInfo.getObjectId());

if (noteInfo.getObjectId() == null) {
Log.i(TAG, "into : test id = null");
noteInfo.save(getContext(), new SaveListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,14 @@ public void onDestroyView() {
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return super.onCreateView(inflater, container, savedInstanceState);
}

public void setIsTrial(boolean isTrial) {
getContext().getSharedPreferences(TFragmentActivity.GLOBAL_SETTINGS, 0)
.edit().putBoolean(TFragmentActivity.IS_TRIAL, isTrial).commit();
}

public boolean getIsTrial() {
return getContext().getSharedPreferences(TFragmentActivity.GLOBAL_SETTINGS, 0)
.getBoolean(TFragmentActivity.IS_TRIAL, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
* Created by Agent Henry on 2015/5/16.
*/
public abstract class TFragmentActivity extends AppCompatActivity {

protected static final String GLOBAL_SETTINGS = "MR_GLOBAL_SETTINGS";
protected static final String IS_TRIAL = "IS_TRIAL";

protected TFragment mCurrentTFragment;
private boolean mCloseWarned;

Expand Down Expand Up @@ -183,4 +187,14 @@ protected void exitFullScreen() {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
}

public void setIsTrial(boolean isTrial) {
getApplicationContext().getSharedPreferences(GLOBAL_SETTINGS, 0)
.edit().putBoolean(IS_TRIAL, isTrial).commit();
}

public boolean getIsTrial() {
return getApplicationContext().getSharedPreferences(GLOBAL_SETTINGS, 0)
.getBoolean(IS_TRIAL, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ public Bitmap transform(Bitmap source) {
float r = size / 2f;
canvas.drawCircle(r, r, r, paint);

if (borderWidth > 0) {
/* if (borderWidth > 0) {
Paint mBorderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mBorderPaint.setStyle(Paint.Style.STROKE);
mBorderPaint.setColor(borderColor);
mBorderPaint.setStrokeWidth(UiUtils.dipToPx(mContext, borderWidth));
canvas.drawCircle(r, r, r - UiUtils.dipToPx(mContext, borderWidth / 2), mBorderPaint);
}
}*/
squaredBitmap.recycle();
return bitmap;
}
Expand Down
2 changes: 2 additions & 0 deletions reading_routine/src/main/res/layout/drawer_header.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
android:layout_above="@+id/email"
android:layout_marginLeft="@dimen/margin_horizontal"
android:layout_marginStart="@dimen/margin_horizontal"
android:text="user"
android:textAppearance="@style/TextAppearance.AppCompat.Body2" />

<TextView
Expand All @@ -32,5 +33,6 @@
android:layout_marginBottom="@dimen/margin_horizontal"
android:layout_marginLeft="@dimen/margin_horizontal"
android:layout_marginStart="@dimen/margin_horizontal"
android:text="[email protected]"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
</RelativeLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
<string name="error_invalid_account">请输入账号</string>
<string name="error_invalid_password">请输入密码</string>
<string name="error_incorrect_password">密码错误</string>
<string name="error_difference_password">输入密码不一致</string>
<string name="error_field_required">This field is required</string>
</resources>

0 comments on commit 1447fd1

Please sign in to comment.