Search in sources :

Example 1 with DBManager

use of com.kiminonawa.mydiary.db.DBManager in project MyDiary by erttyy8821.

the class DiaryViewerDialogFragment method initData.

private void initData() {
    DBManager dbManager = new DBManager(getActivity());
    dbManager.opeDB();
    Cursor diaryInfoCursor = dbManager.selectDiaryInfoByDiaryId(diaryId);
    //load Time
    calendar = Calendar.getInstance();
    calendar.setTimeInMillis(diaryInfoCursor.getLong(1));
    timeTools = TimeTools.getInstance(getActivity().getApplicationContext());
    sdf = new SimpleDateFormat("HH:mm");
    setDiaryTime();
    if (isEditMode) {
        //Allow to edit diary
        LL_diary_time_information.setOnClickListener(this);
        EDT_diary_title.setText(diaryInfoCursor.getString(2));
    } else {
        String diaryTitleStr = diaryInfoCursor.getString(2);
        if (diaryTitleStr == null || diaryTitleStr.equals("")) {
            diaryTitleStr = getString(R.string.diary_no_title);
        }
        TV_diary_title_content.setText(diaryTitleStr);
    }
    //load location
    String locationName = diaryInfoCursor.getString(7);
    if (locationName != null && !"".equals(locationName)) {
        haveLocation = true;
        IV_diary_location_name_icon.setVisibility(View.VISIBLE);
        TV_diary_location.setText(locationName);
    } else {
        haveLocation = false;
        IV_diary_location_name_icon.setVisibility(View.VISIBLE);
    }
    initLocationIcon();
    setIcon(diaryInfoCursor.getInt(3), diaryInfoCursor.getInt(4));
    diaryInfoCursor.close();
    //Get diary detail
    loadDiaryItemContent(dbManager);
    dbManager.closeDB();
}
Also used : DBManager(com.kiminonawa.mydiary.db.DBManager) Cursor(android.database.Cursor) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with DBManager

use of com.kiminonawa.mydiary.db.DBManager in project MyDiary by erttyy8821.

the class ContactsDetailDialogFragment method deleteContacts.

private void deleteContacts() {
    DBManager dbManager = new DBManager(getActivity());
    dbManager.opeDB();
    dbManager.delContacts(contactsId);
    dbManager.closeDB();
}
Also used : DBManager(com.kiminonawa.mydiary.db.DBManager)

Example 3 with DBManager

use of com.kiminonawa.mydiary.db.DBManager in project MyDiary by erttyy8821.

the class MainActivity method onTopicDelete.

@Override
public void onTopicDelete(final int position) {
    DBManager dbManager = new DBManager(MainActivity.this);
    dbManager.opeDB();
    switch(mainTopicAdapter.getList().get(position).getType()) {
        case ITopic.TYPE_CONTACTS:
            dbManager.delAllContactsInTopic(mainTopicAdapter.getList().get(position).getId());
            break;
        case ITopic.TYPE_MEMO:
            dbManager.delAllMemoInTopic(mainTopicAdapter.getList().get(position).getId());
            dbManager.deleteAllCurrentMemoOrder(mainTopicAdapter.getList().get(position).getId());
            break;
        case ITopic.TYPE_DIARY:
            //Because FOREIGN key is not work in this version,
            //so delete diary item first , then delete diary
            Cursor diaryCursor = dbManager.selectDiaryList(mainTopicAdapter.getList().get(position).getId());
            for (int i = 0; i < diaryCursor.getCount(); i++) {
                dbManager.delAllDiaryItemByDiaryId(diaryCursor.getLong(0));
                diaryCursor.moveToNext();
            }
            diaryCursor.close();
            dbManager.delAllDiaryInTopic(mainTopicAdapter.getList().get(position).getId());
            break;
    }
    //Delete the dir if it exist.
    try {
        FileUtils.deleteDirectory(new FileManager(MainActivity.this, mainTopicAdapter.getList().get(position).getType(), mainTopicAdapter.getList().get(position).getId()).getDir());
    } catch (IOException e) {
        //Do nothing if delete fail
        e.printStackTrace();
    }
    dbManager.delTopic(mainTopicAdapter.getList().get(position).getId());
    //Don't delete the topic order, it will be refreshed next moving time.
    dbManager.closeDB();
    //Search for remove the topiclist
    for (int i = 0; i < topicList.size(); i++) {
        if (topicList.get(i).getId() == mainTopicAdapter.getList().get(position).getId()) {
            topicList.remove(i);
            break;
        }
    }
    //remove the filter list
    mainTopicAdapter.getList().remove(position);
    //Notify recycle view
    mainTopicAdapter.notifyItemRemoved(position);
    mainTopicAdapter.notifyItemRangeChanged(position, mainTopicAdapter.getItemCount());
    //Clear the filter
    EDT_main_topic_search.setText("");
}
Also used : DBManager(com.kiminonawa.mydiary.db.DBManager) IOException(java.io.IOException) Cursor(android.database.Cursor) FileManager(com.kiminonawa.mydiary.shared.FileManager)

Example 4 with DBManager

use of com.kiminonawa.mydiary.db.DBManager in project MyDiary by erttyy8821.

the class MainActivity method TopicUpdated.

@Override
public void TopicUpdated(int position, String newTopicTitle, int color, int topicBgStatus, String newTopicBgFileName) {
    DBManager dbManager = new DBManager(this);
    dbManager.opeDB();
    dbManager.updateTopic(mainTopicAdapter.getList().get(position).getId(), newTopicTitle, color);
    dbManager.closeDB();
    //Update filter list
    mainTopicAdapter.getList().get(position).setTitle(newTopicTitle);
    mainTopicAdapter.getList().get(position).setColor(color);
    mainTopicAdapter.notifyDataSetChanged(false);
    updateTopicBg(position, topicBgStatus, newTopicBgFileName);
    //Clear the filter
    EDT_main_topic_search.setText("");
}
Also used : DBManager(com.kiminonawa.mydiary.db.DBManager)

Example 5 with DBManager

use of com.kiminonawa.mydiary.db.DBManager in project MyDiary by erttyy8821.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //Set layout
    setContentView(R.layout.activity_main);
    //For set status bar
    ChinaPhoneHelper.setStatusBar(this, true);
    themeManager = ThemeManager.getInstance();
    LL_main_profile = (LinearLayout) findViewById(R.id.LL_main_profile);
    LL_main_profile.setOnClickListener(this);
    IV_main_profile_picture = (ImageView) findViewById(R.id.IV_main_profile_picture);
    TV_main_profile_username = (TextView) findViewById(R.id.TV_main_profile_username);
    EDT_main_topic_search = (EditText) findViewById(R.id.EDT_main_topic_search);
    EDT_main_topic_search.addTextChangedListener(this);
    IV_main_setting = (ImageView) findViewById(R.id.IV_main_setting);
    IV_main_setting.setOnClickListener(this);
    RecyclerView_topic = (RecyclerView) findViewById(R.id.RecyclerView_topic);
    topicList = new ArrayList<>();
    dbManager = new DBManager(MainActivity.this);
    initProfile();
    initBottomBar();
    initTopicAdapter();
    loadProfilePicture();
    //Init topic adapter
    loadTopic();
    mainTopicAdapter.notifyDataSetChanged(true);
    //Release note dialog
    if (getIntent().getBooleanExtra("showReleaseNote", false)) {
        ReleaseNoteDialogFragment releaseNoteDialogFragment = new ReleaseNoteDialogFragment();
        releaseNoteDialogFragment.show(getSupportFragmentManager(), "releaseNoteDialogFragment");
    }
}
Also used : DBManager(com.kiminonawa.mydiary.db.DBManager)

Aggregations

DBManager (com.kiminonawa.mydiary.db.DBManager)13 Cursor (android.database.Cursor)3 FileManager (com.kiminonawa.mydiary.shared.FileManager)2 IOException (java.io.IOException)2 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 EntriesEntity (com.kiminonawa.mydiary.entries.entries.EntriesEntity)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1