Search in sources :

Example 1 with DatabaseHandler

use of io.praveen.typenote.SQLite.DatabaseHandler in project Android-NotesApp by HelloPraveen.

the class NoteActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_note);
    interstitialAd = new InterstitialAd(NoteActivity.this);
    interstitialAd.setAdUnitId("ca-app-pub-8429477298745270/2004640333");
    interstitialAd.loadAd(new AdRequest.Builder().build());
    intent2 = new Intent(NoteActivity.this, MainActivity.class);
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(NoteActivity.this);
    CalligraphyConfig.initDefault(new CalligraphyConfig.Builder().setDefaultFontPath("fonts/whitney.ttf").setFontAttrId(R.attr.fontPath).build());
    Typeface font2 = Typeface.createFromAsset(getAssets(), "fonts/whitney.ttf");
    SpannableStringBuilder SS = new SpannableStringBuilder("Add Note");
    SS.setSpan(new CustomTypefaceSpan("", font2), 0, SS.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setTitle(SS);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }
    boolean b = preferences.getBoolean("shortcut", true);
    premium = preferences.getInt("premium", 0);
    if (!b) {
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
            int notificationId = 1;
            NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
            String channelId = "TN_1";
            String channelName = "Type Note Shortcuts";
            @SuppressLint("WrongConstant") NotificationChannel mChannel = new NotificationChannel(channelId, channelName, 3);
            if (notificationManager != null) {
                mChannel.setSound(null, null);
                notificationManager.createNotificationChannel(mChannel);
            }
            Intent intent = new Intent(this, NoteActivity.class);
            intent.putExtra("IS_FROM_NOTIFICATION", true);
            @SuppressLint("WrongConstant") PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, intent, NotificationManager.IMPORTANCE_LOW);
            NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext());
            builder.setContentTitle("Tap to add a note");
            builder.setContentText("Note something productive today.");
            builder.setContentIntent(pendingIntent);
            builder.setTicker("Add Notes");
            builder.setChannelId(channelId);
            builder.setColor(getResources().getColor(R.color.colorPrimary));
            builder.setOngoing(true);
            builder.setAutoCancel(true);
            builder.setSmallIcon(R.drawable.notification_white);
            builder.setPriority(Notification.PRIORITY_MAX);
            TaskStackBuilder stackBuilder = TaskStackBuilder.create(getApplicationContext());
            stackBuilder.addNextIntent(intent);
            PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
            builder.setContentIntent(resultPendingIntent);
            if (notificationManager != null)
                notificationManager.notify(notificationId, builder.build());
        } else {
            Intent intent = new Intent(this, NoteActivity.class);
            intent.putExtra("IS_FROM_NOTIFICATION", true);
            PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, intent, 0);
            Notification.Builder builder = new Notification.Builder(getApplicationContext());
            builder.setContentTitle("Tap to add a note");
            builder.setContentText("Note something productive today.");
            builder.setContentIntent(pendingIntent);
            builder.setTicker("Add Notes");
            builder.setOngoing(true);
            builder.setColor(getResources().getColor(R.color.colorPrimary));
            builder.setAutoCancel(true);
            builder.setSmallIcon(R.drawable.notification_white);
            builder.setPriority(Notification.PRIORITY_MAX);
            Notification notification = builder.build();
            NotificationManager notificationManger = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            if (notificationManger != null)
                notificationManger.notify(1, notification);
        }
    }
    FloatingActionButton fab = findViewById(R.id.add_fab);
    text = findViewById(R.id.add_text);
    title = findViewById(R.id.add_title);
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(@NonNull View v) {
            String note = text.getText().toString();
            Title = title.getText().toString();
            if (note.length() > 0) {
                Calendar c = Calendar.getInstance();
                @SuppressLint("SimpleDateFormat") SimpleDateFormat df = new SimpleDateFormat("HH:mm dd/MM/yyyy");
                String formattedDate = df.format(c.getTime());
                DatabaseHandler db = new DatabaseHandler(NoteActivity.this);
                db.addNote(new Note(note, formattedDate, imp, Title));
                intent2.putExtra("note", true);
                intent2.putExtra("new", true);
                if (interstitialAd.isLoaded() && premium != 1) {
                    interstitialAd.show();
                    interstitialAd.setAdListener(new AdListener() {

                        @Override
                        public void onAdClosed() {
                            startActivity(intent2);
                            finish();
                        }
                    });
                } else {
                    startActivity(intent2);
                    finish();
                }
            } else {
                Snackbar.make(v, "Note is empty!", Snackbar.LENGTH_SHORT).show();
            }
        }
    });
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) TaskStackBuilder(android.app.TaskStackBuilder) Notification(android.app.Notification) DatabaseHandler(io.praveen.typenote.SQLite.DatabaseHandler) NotificationCompat(android.support.v4.app.NotificationCompat) FloatingActionButton(android.support.design.widget.FloatingActionButton) InterstitialAd(com.google.android.gms.ads.InterstitialAd) NotificationManager(android.app.NotificationManager) SharedPreferences(android.content.SharedPreferences) Typeface(android.graphics.Typeface) Calendar(java.util.Calendar) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) View(android.view.View) SuppressLint(android.annotation.SuppressLint) AdListener(com.google.android.gms.ads.AdListener) NotificationChannel(android.app.NotificationChannel) Note(io.praveen.typenote.SQLite.Note) SuppressLint(android.annotation.SuppressLint) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.app.TaskStackBuilder) SimpleDateFormat(java.text.SimpleDateFormat) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 2 with DatabaseHandler

use of io.praveen.typenote.SQLite.DatabaseHandler in project Android-NotesApp by HelloPraveen.

the class BinActivity method onCreate.

@TargetApi(Build.VERSION_CODES.O)
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bin);
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(BinActivity.this);
    premium = preferences.getInt("premium", 0);
    interstitialAd = new InterstitialAd(BinActivity.this);
    interstitialAd.setAdUnitId("ca-app-pub-8429477298745270/2004640333");
    interstitialAd.loadAd(new AdRequest.Builder().build());
    i = new Intent(BinActivity.this, MainActivity.class);
    CalligraphyConfig.initDefault(new CalligraphyConfig.Builder().setDefaultFontPath("fonts/whitney.ttf").setFontAttrId(R.attr.fontPath).build());
    Typeface font2 = Typeface.createFromAsset(getAssets(), "fonts/whitney.ttf");
    SpannableStringBuilder SS = new SpannableStringBuilder("Trash");
    SS.setSpan(new CustomTypefaceSpan("", font2), 0, SS.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setTitle(SS);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }
    final BinDatabaseHandler db = new BinDatabaseHandler(this);
    l = db.getAllNotes();
    final RecyclerView recyclerView = findViewById(R.id.binRecyclerView);
    final RelativeLayout rl = findViewById(R.id.binPlaceholder);
    if (l.isEmpty()) {
        recyclerView.setVisibility(View.GONE);
        rl.setVisibility(View.VISIBLE);
    }
    NoteAdapter mAdapter = new NoteAdapter(l);
    RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
    recyclerView.setLayoutManager(mLayoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL));
    recyclerView.setAdapter(mAdapter);
    recyclerView.addOnItemTouchListener(new RecyclerTouchListener(getApplicationContext(), new ClickListener() {

        @Override
        public void onClick(View view, final int position) {
            final Note note = l.get(position);
            final String mNote = note.getNote();
            final int mStar = note.getStar();
            final String mDate = note.getDate();
            final String mTitle = note.getTitle();
            new MaterialStyledDialog.Builder(BinActivity.this).setIcon(R.drawable.ic_settings_backup_restore).setDescription("You may choose to restore your note or delete it permanently!").setPositiveText("DELETE").onPositive(new MaterialDialog.SingleButtonCallback() {

                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    BinDatabaseHandler db = new BinDatabaseHandler(BinActivity.this);
                    List<Note> l2 = db.getAllNotes();
                    final Note note2 = l2.get(position);
                    db.deleteNote(note2);
                    i.putExtra("note", true);
                    i.putExtra("delete", true);
                    if (interstitialAd.isLoaded() && premium != 1) {
                        interstitialAd.show();
                        interstitialAd.setAdListener(new AdListener() {

                            @Override
                            public void onAdClosed() {
                                startActivity(i);
                                finish();
                            }
                        });
                    } else {
                        startActivity(i);
                        finish();
                    }
                }
            }).setNegativeText("RESTORE").onNegative(new MaterialDialog.SingleButtonCallback() {

                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    BinDatabaseHandler db = new BinDatabaseHandler(BinActivity.this);
                    DatabaseHandler db2 = new DatabaseHandler(BinActivity.this);
                    db2.addNote(new Note(mNote, mDate, mStar, mTitle));
                    List<Note> l2 = db.getAllNotes();
                    final Note note2 = l2.get(position);
                    db.deleteNote(note2);
                    i.putExtra("note", true);
                    i.putExtra("restore", true);
                    if (interstitialAd.isLoaded() && premium != 1) {
                        interstitialAd.show();
                        interstitialAd.setAdListener(new AdListener() {

                            @Override
                            public void onAdClosed() {
                                startActivity(i);
                                finish();
                            }
                        });
                    } else {
                        startActivity(i);
                        finish();
                    }
                }
            }).setNeutralText("DISMISS").onNeutral(new MaterialDialog.SingleButtonCallback() {

                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                }
            }).setHeaderColor(R.color.colorPrimary).withIconAnimation(false).withDivider(true).show();
        }
    }));
}
Also used : BinDatabaseHandler(io.praveen.typenote.SQLite.BinDatabaseHandler) SpannableStringBuilder(android.text.SpannableStringBuilder) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) BinDatabaseHandler(io.praveen.typenote.SQLite.BinDatabaseHandler) DatabaseHandler(io.praveen.typenote.SQLite.DatabaseHandler) NoteAdapter(io.praveen.typenote.SQLite.NoteAdapter) InterstitialAd(com.google.android.gms.ads.InterstitialAd) List(java.util.List) ClickListener(io.praveen.typenote.SQLite.ClickListener) RecyclerTouchListener(io.praveen.typenote.SQLite.RecyclerTouchListener) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) SharedPreferences(android.content.SharedPreferences) Typeface(android.graphics.Typeface) Intent(android.content.Intent) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) AdListener(com.google.android.gms.ads.AdListener) DialogAction(com.afollestad.materialdialogs.DialogAction) Note(io.praveen.typenote.SQLite.Note) RelativeLayout(android.widget.RelativeLayout) RecyclerView(android.support.v7.widget.RecyclerView) SpannableStringBuilder(android.text.SpannableStringBuilder) TargetApi(android.annotation.TargetApi)

Example 3 with DatabaseHandler

use of io.praveen.typenote.SQLite.DatabaseHandler in project Android-NotesApp by HelloPraveen.

the class EditActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_edit);
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(EditActivity.this);
    premium = preferences.getInt("premium", 0);
    interstitialAd = new InterstitialAd(EditActivity.this);
    interstitialAd.setAdUnitId("ca-app-pub-8429477298745270/2004640333");
    interstitialAd.loadAd(new AdRequest.Builder().build());
    intent = new Intent(EditActivity.this, MainActivity.class);
    CalligraphyConfig.initDefault(new CalligraphyConfig.Builder().setDefaultFontPath("fonts/whitney.ttf").setFontAttrId(R.attr.fontPath).build());
    Typeface font2 = Typeface.createFromAsset(getAssets(), "fonts/whitney.ttf");
    SpannableStringBuilder SS = new SpannableStringBuilder("Edit Note");
    SS.setSpan(new CustomTypefaceSpan("", font2), 0, SS.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setTitle(SS);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }
    String noteText = "", noteTitle = "";
    if (getIntent().getExtras() != null) {
        noteText = getIntent().getExtras().getString("note");
        noteTitle = getIntent().getExtras().getString("title");
    }
    FloatingActionButton fab = findViewById(R.id.edit_fab);
    text = findViewById(R.id.edit_text);
    title = findViewById(R.id.edit_title);
    text.setText(noteText);
    title.setText(noteTitle);
    text.setSelection(noteText != null ? noteText.length() : 0);
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(@NonNull View v) {
            String note = text.getText().toString();
            Title = title.getText().toString();
            if (note.length() > 0) {
                Calendar c = Calendar.getInstance();
                SimpleDateFormat df = new SimpleDateFormat("HH:mm dd/MM/yyyy", Locale.ENGLISH);
                String formattedDate = df.format(c.getTime());
                int id = 0;
                if (getIntent().getExtras() != null) {
                    id = getIntent().getExtras().getInt("id");
                }
                DatabaseHandler db = new DatabaseHandler(EditActivity.this);
                db.updateNote(new Note(id, note, formattedDate, imp, Title));
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                intent.putExtra("edit", true);
                intent.putExtra("note", true);
                if (interstitialAd.isLoaded() && premium != 1) {
                    interstitialAd.show();
                    interstitialAd.setAdListener(new AdListener() {

                        @Override
                        public void onAdClosed() {
                            startActivity(intent);
                            finish();
                        }
                    });
                } else {
                    startActivity(intent);
                    finish();
                }
            } else
                Snackbar.make(v, "Note is empty!", Snackbar.LENGTH_SHORT).show();
        }
    });
}
Also used : SharedPreferences(android.content.SharedPreferences) Typeface(android.graphics.Typeface) SpannableStringBuilder(android.text.SpannableStringBuilder) Calendar(java.util.Calendar) Intent(android.content.Intent) View(android.view.View) AdListener(com.google.android.gms.ads.AdListener) DatabaseHandler(io.praveen.typenote.SQLite.DatabaseHandler) Note(io.praveen.typenote.SQLite.Note) FloatingActionButton(android.support.design.widget.FloatingActionButton) InterstitialAd(com.google.android.gms.ads.InterstitialAd) SimpleDateFormat(java.text.SimpleDateFormat) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 4 with DatabaseHandler

use of io.praveen.typenote.SQLite.DatabaseHandler in project Android-NotesApp by HelloPraveenIO.

the class NoteActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_note);
    interstitialAd = new InterstitialAd(NoteActivity.this);
    interstitialAd.setAdUnitId("ca-app-pub-8429477298745270/2004640333");
    interstitialAd.loadAd(new AdRequest.Builder().build());
    intent2 = new Intent(NoteActivity.this, MainActivity.class);
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(NoteActivity.this);
    CalligraphyConfig.initDefault(new CalligraphyConfig.Builder().setDefaultFontPath("fonts/whitney.ttf").setFontAttrId(R.attr.fontPath).build());
    Typeface font2 = Typeface.createFromAsset(getAssets(), "fonts/whitney.ttf");
    SpannableStringBuilder SS = new SpannableStringBuilder("Add Note");
    SS.setSpan(new CustomTypefaceSpan("", font2), 0, SS.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setTitle(SS);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }
    boolean b = preferences.getBoolean("shortcut", true);
    premium = preferences.getInt("premium", 0);
    if (!b) {
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
            int notificationId = 1;
            NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
            String channelId = "TN_1";
            String channelName = "Type Note Shortcuts";
            @SuppressLint("WrongConstant") NotificationChannel mChannel = new NotificationChannel(channelId, channelName, 3);
            if (notificationManager != null) {
                mChannel.setSound(null, null);
                notificationManager.createNotificationChannel(mChannel);
            }
            Intent intent = new Intent(this, NoteActivity.class);
            intent.putExtra("IS_FROM_NOTIFICATION", true);
            @SuppressLint("WrongConstant") PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, intent, NotificationManager.IMPORTANCE_LOW);
            NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext());
            builder.setContentTitle("Tap to add a note");
            builder.setContentText("Note something productive today.");
            builder.setContentIntent(pendingIntent);
            builder.setTicker("Add Notes");
            builder.setChannelId(channelId);
            builder.setColor(getResources().getColor(R.color.colorPrimary));
            builder.setOngoing(true);
            builder.setAutoCancel(true);
            builder.setSmallIcon(R.drawable.notification_white);
            builder.setPriority(Notification.PRIORITY_MAX);
            TaskStackBuilder stackBuilder = TaskStackBuilder.create(getApplicationContext());
            stackBuilder.addNextIntent(intent);
            PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
            builder.setContentIntent(resultPendingIntent);
            if (notificationManager != null)
                notificationManager.notify(notificationId, builder.build());
        } else {
            Intent intent = new Intent(this, NoteActivity.class);
            intent.putExtra("IS_FROM_NOTIFICATION", true);
            PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, intent, 0);
            Notification.Builder builder = new Notification.Builder(getApplicationContext());
            builder.setContentTitle("Tap to add a note");
            builder.setContentText("Note something productive today.");
            builder.setContentIntent(pendingIntent);
            builder.setTicker("Add Notes");
            builder.setOngoing(true);
            builder.setColor(getResources().getColor(R.color.colorPrimary));
            builder.setAutoCancel(true);
            builder.setSmallIcon(R.drawable.notification_white);
            builder.setPriority(Notification.PRIORITY_MAX);
            Notification notification = builder.build();
            NotificationManager notificationManger = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            if (notificationManger != null)
                notificationManger.notify(1, notification);
        }
    }
    FloatingActionButton fab = findViewById(R.id.add_fab);
    text = findViewById(R.id.add_text);
    title = findViewById(R.id.add_title);
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(@NonNull View v) {
            String note = text.getText().toString();
            Title = title.getText().toString();
            if (note.length() > 0) {
                Calendar c = Calendar.getInstance();
                @SuppressLint("SimpleDateFormat") SimpleDateFormat df = new SimpleDateFormat("HH:mm dd/MM/yyyy");
                String formattedDate = df.format(c.getTime());
                DatabaseHandler db = new DatabaseHandler(NoteActivity.this);
                db.addNote(new Note(note, formattedDate, imp, Title));
                intent2.putExtra("note", true);
                intent2.putExtra("new", true);
                if (interstitialAd.isLoaded() && premium != 1) {
                    interstitialAd.show();
                    interstitialAd.setAdListener(new AdListener() {

                        @Override
                        public void onAdClosed() {
                            startActivity(intent2);
                            finish();
                        }
                    });
                } else {
                    startActivity(intent2);
                    finish();
                }
            } else {
                Snackbar.make(v, "Note is empty!", Snackbar.LENGTH_SHORT).show();
            }
        }
    });
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) TaskStackBuilder(android.app.TaskStackBuilder) Notification(android.app.Notification) DatabaseHandler(io.praveen.typenote.SQLite.DatabaseHandler) NotificationCompat(android.support.v4.app.NotificationCompat) FloatingActionButton(android.support.design.widget.FloatingActionButton) InterstitialAd(com.google.android.gms.ads.InterstitialAd) NotificationManager(android.app.NotificationManager) SharedPreferences(android.content.SharedPreferences) Typeface(android.graphics.Typeface) Calendar(java.util.Calendar) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) View(android.view.View) SuppressLint(android.annotation.SuppressLint) AdListener(com.google.android.gms.ads.AdListener) NotificationChannel(android.app.NotificationChannel) Note(io.praveen.typenote.SQLite.Note) SuppressLint(android.annotation.SuppressLint) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.app.TaskStackBuilder) SimpleDateFormat(java.text.SimpleDateFormat) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 5 with DatabaseHandler

use of io.praveen.typenote.SQLite.DatabaseHandler in project Android-NotesApp by HelloPraveenIO.

the class BinActivity method onCreate.

@TargetApi(Build.VERSION_CODES.O)
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bin);
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(BinActivity.this);
    premium = preferences.getInt("premium", 0);
    interstitialAd = new InterstitialAd(BinActivity.this);
    interstitialAd.setAdUnitId("ca-app-pub-8429477298745270/2004640333");
    interstitialAd.loadAd(new AdRequest.Builder().build());
    i = new Intent(BinActivity.this, MainActivity.class);
    CalligraphyConfig.initDefault(new CalligraphyConfig.Builder().setDefaultFontPath("fonts/whitney.ttf").setFontAttrId(R.attr.fontPath).build());
    Typeface font2 = Typeface.createFromAsset(getAssets(), "fonts/whitney.ttf");
    SpannableStringBuilder SS = new SpannableStringBuilder("Trash");
    SS.setSpan(new CustomTypefaceSpan("", font2), 0, SS.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setTitle(SS);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }
    final BinDatabaseHandler db = new BinDatabaseHandler(this);
    l = db.getAllNotes();
    final RecyclerView recyclerView = findViewById(R.id.binRecyclerView);
    final RelativeLayout rl = findViewById(R.id.binPlaceholder);
    if (l.isEmpty()) {
        recyclerView.setVisibility(View.GONE);
        rl.setVisibility(View.VISIBLE);
    }
    NoteAdapter mAdapter = new NoteAdapter(l);
    RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
    recyclerView.setLayoutManager(mLayoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL));
    recyclerView.setAdapter(mAdapter);
    recyclerView.addOnItemTouchListener(new RecyclerTouchListener(getApplicationContext(), new ClickListener() {

        @Override
        public void onClick(View view, final int position) {
            final Note note = l.get(position);
            final String mNote = note.getNote();
            final int mStar = note.getStar();
            final String mDate = note.getDate();
            final String mTitle = note.getTitle();
            new MaterialStyledDialog.Builder(BinActivity.this).setIcon(R.drawable.ic_settings_backup_restore).setDescription("You may choose to restore your note or delete it permanently!").setPositiveText("DELETE").onPositive(new MaterialDialog.SingleButtonCallback() {

                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    BinDatabaseHandler db = new BinDatabaseHandler(BinActivity.this);
                    List<Note> l2 = db.getAllNotes();
                    final Note note2 = l2.get(position);
                    db.deleteNote(note2);
                    i.putExtra("note", true);
                    i.putExtra("delete", true);
                    if (interstitialAd.isLoaded() && premium != 1) {
                        interstitialAd.show();
                        interstitialAd.setAdListener(new AdListener() {

                            @Override
                            public void onAdClosed() {
                                startActivity(i);
                                finish();
                            }
                        });
                    } else {
                        startActivity(i);
                        finish();
                    }
                }
            }).setNegativeText("RESTORE").onNegative(new MaterialDialog.SingleButtonCallback() {

                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    BinDatabaseHandler db = new BinDatabaseHandler(BinActivity.this);
                    DatabaseHandler db2 = new DatabaseHandler(BinActivity.this);
                    db2.addNote(new Note(mNote, mDate, mStar, mTitle));
                    List<Note> l2 = db.getAllNotes();
                    final Note note2 = l2.get(position);
                    db.deleteNote(note2);
                    i.putExtra("note", true);
                    i.putExtra("restore", true);
                    if (interstitialAd.isLoaded() && premium != 1) {
                        interstitialAd.show();
                        interstitialAd.setAdListener(new AdListener() {

                            @Override
                            public void onAdClosed() {
                                startActivity(i);
                                finish();
                            }
                        });
                    } else {
                        startActivity(i);
                        finish();
                    }
                }
            }).setNeutralText("DISMISS").onNeutral(new MaterialDialog.SingleButtonCallback() {

                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                }
            }).setHeaderColor(R.color.colorPrimary).withIconAnimation(false).withDivider(true).show();
        }
    }));
}
Also used : BinDatabaseHandler(io.praveen.typenote.SQLite.BinDatabaseHandler) SpannableStringBuilder(android.text.SpannableStringBuilder) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) BinDatabaseHandler(io.praveen.typenote.SQLite.BinDatabaseHandler) DatabaseHandler(io.praveen.typenote.SQLite.DatabaseHandler) NoteAdapter(io.praveen.typenote.SQLite.NoteAdapter) InterstitialAd(com.google.android.gms.ads.InterstitialAd) List(java.util.List) ClickListener(io.praveen.typenote.SQLite.ClickListener) RecyclerTouchListener(io.praveen.typenote.SQLite.RecyclerTouchListener) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) SharedPreferences(android.content.SharedPreferences) Typeface(android.graphics.Typeface) Intent(android.content.Intent) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) AdListener(com.google.android.gms.ads.AdListener) DialogAction(com.afollestad.materialdialogs.DialogAction) Note(io.praveen.typenote.SQLite.Note) RelativeLayout(android.widget.RelativeLayout) RecyclerView(android.support.v7.widget.RecyclerView) SpannableStringBuilder(android.text.SpannableStringBuilder) TargetApi(android.annotation.TargetApi)

Aggregations

Intent (android.content.Intent)10 DatabaseHandler (io.praveen.typenote.SQLite.DatabaseHandler)10 Note (io.praveen.typenote.SQLite.Note)10 View (android.view.View)8 SharedPreferences (android.content.SharedPreferences)6 Typeface (android.graphics.Typeface)6 SpannableStringBuilder (android.text.SpannableStringBuilder)6 AdListener (com.google.android.gms.ads.AdListener)6 InterstitialAd (com.google.android.gms.ads.InterstitialAd)6 SuppressLint (android.annotation.SuppressLint)4 PendingIntent (android.app.PendingIntent)4 FloatingActionButton (android.support.design.widget.FloatingActionButton)4 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)4 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)4 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)4 RecyclerView (android.support.v7.widget.RecyclerView)4 RelativeLayout (android.widget.RelativeLayout)4 BinDatabaseHandler (io.praveen.typenote.SQLite.BinDatabaseHandler)4 ClickListener (io.praveen.typenote.SQLite.ClickListener)4 NoteAdapter (io.praveen.typenote.SQLite.NoteAdapter)4