// Path: app/src/main/java/com/apps/anker/facepunchdroid/Adapters/PinnedItemsAdapter.java
// public class PinnedItemsAdapter extends ArrayAdapter<PinnedItem> {
// 
//     private List<PinnedItem> pinnedItems;
// 
//     public PinnedItemsAdapter(Context context, int resource, List<PinnedItem> objects) {
//         super(context, resource, objects);
//         pinnedItems = objects;
//     }
// 
//     @Override
//     public View getView(int position, View convertView, ViewGroup parent) {
// 
//         int dbPosition = position + 1;
// 
//         if(convertView == null) {
//             convertView = LayoutInflater.from(getContext()).inflate(R.layout.pinneditem_list_item, parent, false);
//         }
// 
//         Log.d("Position:", Integer.toString(position));
//         PinnedItem pitem = pinnedItems.get(position);
// 
//         convertView.setTag(position);
//         TextView titleText = (TextView) convertView.findViewById(R.id.item_title);
//         titleText.setText(pitem.getTitle());
// 
//         return convertView;
//     }
// }
// 
// Path: app/src/main/java/com/apps/anker/facepunchdroid/Migrations/MainMigration.java
// public class MainMigration {
//     // Example migration adding a new class
//     static RealmMigration migration = new RealmMigration() {
//         @Override
//         public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {
// 
//             // DynamicRealm exposes an editable schema
//             RealmSchema schema = realm.getSchema();
// 
//             // Migrate to version 1: Add a new class.
//             // Example:
//             // public Person extends RealmObject {
//             //     private String name;
//             //     private int age;
//             //     // getters and setters left out for brevity
//             // }
//             if (oldVersion == 0) {
//                 schema.create("UserScript")
//                         .addField("title", String.class)
//                         .addField("url", String.class);
//                 oldVersion++;
//             }
// 
//             if (oldVersion == 1) {
//                 schema.get("UserScript")
//                         .addField("javascript", String.class);
//                 oldVersion++;
//             }
//         }
//     };
// 
//     public static RealmMigration getMigration() {
//         return migration;
//     }
// 
// }
// 
// Path: app/src/main/java/com/apps/anker/facepunchdroid/Tools/ShortcutsManager.java
// public class ShortcutsManager {
//     public static void updateShortcuts(Realm realm, Activity activity) {
//         /**
//          * Shortcuts!
//          */
//         if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
//             ShortcutManager shortcutManager = activity.getSystemService(ShortcutManager.class);
// 
//             ArrayList<ShortcutInfo> shortcutlist = new ArrayList<>();
// 
//             // Get Pinned items
//             RealmResults<PinnedItem> pinnedItems = realm.where(PinnedItem.class).findAll();
// 
//             if (pinnedItems.size() > 0) {
//                 int count = 0;
//                 for (PinnedItem pitem : pinnedItems) {
//                     Intent linkIntent = new Intent(
//                             Intent.ACTION_VIEW,
//                             Uri.parse(pitem.getUrl()),
//                             activity,
//                             activity.getClass());
// 
//                     linkIntent.putExtra("shortcut", pitem.getUrl());
// 
// 
//                     ShortcutInfo shortcut = new ShortcutInfo.Builder(activity, "shortcut" + count)
//                             .setShortLabel(pitem.getTitle())
//                             .setLongLabel(pitem.getTitle())
//                             .setIcon(Icon.createWithResource(activity, R.drawable.ic_link_black_24dp))
//                             .setIntent(linkIntent)
//                             .build();
// 
//                     shortcutlist.add(shortcut);
//                     count++;
//                 }
// 
//                 shortcutManager.setDynamicShortcuts(shortcutlist);
//             }
//         }
//     }
// }


import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutManager;
import android.graphics.drawable.Icon;
import android.os.Build;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.InputType;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.Toast;
import com.apps.anker.facepunchdroid.Adapters.PinnedItemsAdapter;
import com.apps.anker.facepunchdroid.Migrations.MainMigration;
import com.apps.anker.facepunchdroid.Tools.ShortcutsManager;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import io.realm.Realm;
import io.realm.RealmConfiguration;
import io.realm.RealmResults;
                                            titlebuilder.setTitle(R.string.dialog_enternewtitle_title);


                                            // Set up the input
                                            final EditText titleinput = new EditText(mActivity);

                                            titleinput.setText(pinnedItems.get(position).getTitle());

                                            // Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
                                            titleinput.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);

                                            titlebuilder.setView(titleinput);

                                            // Set up the buttons
                                            titlebuilder.setPositiveButton(R.string.answer_ok, new DialogInterface.OnClickListener() {
                                                @Override
                                                public void onClick(DialogInterface dialog, int which) {
                                                    realm.beginTransaction();
                                                    pinnedItems.get(position).setTitle(titleinput.getText().toString());
                                                    realm.commitTransaction();

                                                    Snackbar.make(mlayout , R.string.pinned_item_was_updated, Snackbar.LENGTH_LONG).show();
                                                    updateShortcuts();
                                                }
                                            });
                                            titlebuilder.setNegativeButton(R.string.answer_cancel, new DialogInterface.OnClickListener() {
                                                @Override
                                                public void onClick(DialogInterface dialog, int which) {
                                                    dialog.cancel();
                                                }
// Path: app/src/main/java/com/apps/anker/facepunchdroid/Adapters/PinnedItemsAdapter.java
// public class PinnedItemsAdapter extends ArrayAdapter<PinnedItem> {
// 
//     private List<PinnedItem> pinnedItems;
// 
//     public PinnedItemsAdapter(Context context, int resource, List<PinnedItem> objects) {
//         super(context, resource, objects);
//         pinnedItems = objects;
//     }
// 
//     @Override
//     public View getView(int position, View convertView, ViewGroup parent) {
// 
//         int dbPosition = position + 1;
// 
//         if(convertView == null) {
//             convertView = LayoutInflater.from(getContext()).inflate(R.layout.pinneditem_list_item, parent, false);
//         }
// 
//         Log.d("Position:", Integer.toString(position));
//         PinnedItem pitem = pinnedItems.get(position);
// 
//         convertView.setTag(position);
//         TextView titleText = (TextView) convertView.findViewById(R.id.item_title);
//         titleText.setText(pitem.getTitle());
// 
//         return convertView;
//     }
// }
// 
// Path: app/src/main/java/com/apps/anker/facepunchdroid/Migrations/MainMigration.java
// public class MainMigration {
//     // Example migration adding a new class
//     static RealmMigration migration = new RealmMigration() {
//         @Override
//         public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {
// 
//             // DynamicRealm exposes an editable schema
//             RealmSchema schema = realm.getSchema();
// 
//             // Migrate to version 1: Add a new class.
//             // Example:
//             // public Person extends RealmObject {
//             //     private String name;
//             //     private int age;
//             //     // getters and setters left out for brevity
//             // }
//             if (oldVersion == 0) {
//                 schema.create("UserScript")
//                         .addField("title", String.class)
//                         .addField("url", String.class);
//                 oldVersion++;
//             }
// 
//             if (oldVersion == 1) {
//                 schema.get("UserScript")
//                         .addField("javascript", String.class);
//                 oldVersion++;
//             }
//         }
//     };
// 
//     public static RealmMigration getMigration() {
//         return migration;
//     }
// 
// }
// 
// Path: app/src/main/java/com/apps/anker/facepunchdroid/Tools/ShortcutsManager.java
// public class ShortcutsManager {
//     public static void updateShortcuts(Realm realm, Activity activity) {
//         /**
//          * Shortcuts!
//          */
//         if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
//             ShortcutManager shortcutManager = activity.getSystemService(ShortcutManager.class);
// 
//             ArrayList<ShortcutInfo> shortcutlist = new ArrayList<>();
// 
//             // Get Pinned items
//             RealmResults<PinnedItem> pinnedItems = realm.where(PinnedItem.class).findAll();
// 
//             if (pinnedItems.size() > 0) {
//                 int count = 0;
//                 for (PinnedItem pitem : pinnedItems) {
//                     Intent linkIntent = new Intent(
//                             Intent.ACTION_VIEW,
//                             Uri.parse(pitem.getUrl()),
//                             activity,
//                             activity.getClass());
// 
//                     linkIntent.putExtra("shortcut", pitem.getUrl());
// 
// 
//                     ShortcutInfo shortcut = new ShortcutInfo.Builder(activity, "shortcut" + count)
//                             .setShortLabel(pitem.getTitle())
//                             .setLongLabel(pitem.getTitle())
//                             .setIcon(Icon.createWithResource(activity, R.drawable.ic_link_black_24dp))
//                             .setIntent(linkIntent)
//                             .build();
// 
//                     shortcutlist.add(shortcut);
//                     count++;
//                 }
// 
//                 shortcutManager.setDynamicShortcuts(shortcutlist);
//             }
//         }
//     }
// }


// Path: app/src/main/java/com/apps/anker/facepunchdroid/EditPinnedItemsActivity.java
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutManager;
import android.graphics.drawable.Icon;
import android.os.Build;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.InputType;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.Toast;
import com.apps.anker.facepunchdroid.Adapters.PinnedItemsAdapter;
import com.apps.anker.facepunchdroid.Migrations.MainMigration;
import com.apps.anker.facepunchdroid.Tools.ShortcutsManager;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import io.realm.Realm;
import io.realm.RealmConfiguration;
import io.realm.RealmResults;

                                            titlebuilder.setTitle(R.string.dialog_enternewtitle_title);


                                            // Set up the input
                                            final EditText titleinput = new EditText(mActivity);

                                            titleinput.setText(pinnedItems.get(position).getTitle());

                                            // Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
                                            titleinput.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);

                                            titlebuilder.setView(titleinput);

                                            // Set up the buttons
                                            titlebuilder.setPositiveButton(R.string.answer_ok, new DialogInterface.OnClickListener() {
                                                @Override
                                                public void onClick(DialogInterface dialog, int which) {
                                                    realm.beginTransaction();
                                                    pinnedItems.get(position).setTitle(titleinput.getText().toString());
                                                    realm.commitTransaction();

                                                    Snackbar.make(mlayout , R.string.pinned_item_was_updated, Snackbar.LENGTH_LONG).show();
                                                    updateShortcuts();
                                                }
                                            });
                                            titlebuilder.setNegativeButton(R.string.answer_cancel, new DialogInterface.OnClickListener() {
                                                @Override
                                                public void onClick(DialogInterface dialog, int which) {
                                                    dialog.cancel();
                                                }
                                            });