// Path: app/src/main/java/com/secuso/privacyfriendlycodescanner/qrscanner/database/AppRepository.java
// public class AppRepository {
// 
//     private static AppRepository INSTANCE = null;
// 
//     private final AppDatabase appDatabase;
// 
//     private final ExecutorService executor = Executors.newSingleThreadExecutor();
// 
//     public synchronized static AppRepository getInstance(Context context) {
//         if(INSTANCE == null) {
//             INSTANCE = new AppRepository(context);
//         }
//         return INSTANCE;
//     }
// 
//     private AppRepository(Context context) {
//         this.appDatabase = AppDatabase.getInstance(context);
//     }
// 
//     public void deleteHistoryEntry(HistoryItem entry) {
//         executor.execute(() -> appDatabase.historyDao().delete(entry));
//     }
// 
//     public void insertHistoryEntry(HistoryItem entry) {
//         executor.execute(() -> appDatabase.historyDao().insert(entry));
//     }
// 
//     public void updateHistoryEntry(HistoryItem entry) {
//         executor.execute(() -> appDatabase.historyDao().update(entry));
//     }
// 
//     public LiveData<List<HistoryItem>> getHistoryEntriesLiveData() {
//         return appDatabase.historyDao().getAllLiveData();
//     }
// 
//     public void deleteAllHistoryEntries() {
//         executor.execute(() -> appDatabase.historyDao().deleteAll());
//     }
// }
// 
// Path: app/src/main/java/com/secuso/privacyfriendlycodescanner/qrscanner/ui/adapter/HistoryAdapter.java
// public class HistoryAdapter extends RecyclerView.Adapter<HistoryAdapter.HistoryItemViewHolder> {
// 
//     private final Context context;
//     private final List<HistoryItem> historyEntries;
// 
//     public HistoryAdapter(Context context) {
//         this.context = context;
//         this.historyEntries = new ArrayList<>();
// 
//         setHasStableIds(true);
//     }
// 
//     public void setHistoryEntries(List<HistoryItem> entries) {
//         historyEntries.clear();
//         historyEntries.addAll(entries);
//         notifyDataSetChanged();
//     }
// 
//     @NonNull
//     @Override
//     public HistoryItemViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
//         ItemHistoryCodeBinding binding = DataBindingUtil.inflate(
//                 LayoutInflater.from(viewGroup.getContext()),
//                 R.layout.item_history_code,
//                 viewGroup,
//                 false
//         );
//         return new HistoryItemViewHolder(binding);
//     }
// 
//     @Override
//     public void onBindViewHolder(@NonNull HistoryItemViewHolder historyItemViewHolder, int i) {
//         ItemHistoryCodeBinding binding = historyItemViewHolder.binding;
//         HistoryItemViewModel viewModel = new HistoryItemViewModel(context, historyEntries.get(i));
//         binding.setViewModel(viewModel);
//         binding.itemView.setOnClickListener(viewModel.onClickItem());
//         binding.itemView.setOnLongClickListener(viewModel.onLongClickItem());
// 
//         Bitmap image = historyEntries.get(i).getImage();
//         if(image != null) {
//             Glide.with(context).load(image).placeholder(R.drawable.ic_no_image_accent_24dp).into(binding.itemHistoryImage);
//         } else {
//             Glide.with(context).load(R.drawable.ic_no_image_accent_24dp).into(binding.itemHistoryImage);
//         }
//     }
// 
//     @Override
//     public int getItemCount() {
//         return historyEntries.size();
//     }
// 
//     @Override
//     public long getItemId(int i) {
//         return historyEntries.get(i).get_id();
//     }
// 
//     public static class HistoryItemViewHolder extends RecyclerView.ViewHolder {
//         ItemHistoryCodeBinding binding;
// 
//         public HistoryItemViewHolder(@NonNull ItemHistoryCodeBinding binding) {
//             super(binding.itemView);
//             this.binding = binding;
//         }
//     }
// }
// 
// Path: app/src/main/java/com/secuso/privacyfriendlycodescanner/qrscanner/ui/viewmodel/HistoryViewModel.java
// public class HistoryViewModel extends AndroidViewModel {
// 
//     private final ExecutorService executorService = Executors.newSingleThreadExecutor();
// 
//     private final MediatorLiveData<List<HistoryItem>> historyItemsLiveData = new MediatorLiveData<>();
// 
//     public HistoryViewModel(@NonNull final Application application) {
//         super(application);
// 
//         loadHistories();
//     }
// 
//     public LiveData<List<HistoryItem>> getHistoryItems() {
//         return historyItemsLiveData;
//     }
// 
//     private void loadHistories() {
//         LiveData<List<HistoryItem>> historyEntries = AppRepository.getInstance(getApplication()).getHistoryEntriesLiveData();
//         historyItemsLiveData.addSource(historyEntries, historyItemsLiveData::setValue);
//     }
// }


import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.secuso.privacyfriendlycodescanner.qrscanner.R;
import com.secuso.privacyfriendlycodescanner.qrscanner.database.AppRepository;
import com.secuso.privacyfriendlycodescanner.qrscanner.ui.adapter.HistoryAdapter;
import com.secuso.privacyfriendlycodescanner.qrscanner.ui.viewmodel.HistoryViewModel;
package com.secuso.privacyfriendlycodescanner.qrscanner.ui.activities;




/**
 * History Overview that shows a list of scanned codes.
 *
 * @author Christopher Beckmann
 */
public class HistoryActivity extends AppCompatActivity {

    private HistoryAdapter mHistoryAdapter;
    private RecyclerView mHistoryRecyclerView;
// Path: app/src/main/java/com/secuso/privacyfriendlycodescanner/qrscanner/database/AppRepository.java
// public class AppRepository {
// 
//     private static AppRepository INSTANCE = null;
// 
//     private final AppDatabase appDatabase;
// 
//     private final ExecutorService executor = Executors.newSingleThreadExecutor();
// 
//     public synchronized static AppRepository getInstance(Context context) {
//         if(INSTANCE == null) {
//             INSTANCE = new AppRepository(context);
//         }
//         return INSTANCE;
//     }
// 
//     private AppRepository(Context context) {
//         this.appDatabase = AppDatabase.getInstance(context);
//     }
// 
//     public void deleteHistoryEntry(HistoryItem entry) {
//         executor.execute(() -> appDatabase.historyDao().delete(entry));
//     }
// 
//     public void insertHistoryEntry(HistoryItem entry) {
//         executor.execute(() -> appDatabase.historyDao().insert(entry));
//     }
// 
//     public void updateHistoryEntry(HistoryItem entry) {
//         executor.execute(() -> appDatabase.historyDao().update(entry));
//     }
// 
//     public LiveData<List<HistoryItem>> getHistoryEntriesLiveData() {
//         return appDatabase.historyDao().getAllLiveData();
//     }
// 
//     public void deleteAllHistoryEntries() {
//         executor.execute(() -> appDatabase.historyDao().deleteAll());
//     }
// }
// 
// Path: app/src/main/java/com/secuso/privacyfriendlycodescanner/qrscanner/ui/adapter/HistoryAdapter.java
// public class HistoryAdapter extends RecyclerView.Adapter<HistoryAdapter.HistoryItemViewHolder> {
// 
//     private final Context context;
//     private final List<HistoryItem> historyEntries;
// 
//     public HistoryAdapter(Context context) {
//         this.context = context;
//         this.historyEntries = new ArrayList<>();
// 
//         setHasStableIds(true);
//     }
// 
//     public void setHistoryEntries(List<HistoryItem> entries) {
//         historyEntries.clear();
//         historyEntries.addAll(entries);
//         notifyDataSetChanged();
//     }
// 
//     @NonNull
//     @Override
//     public HistoryItemViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
//         ItemHistoryCodeBinding binding = DataBindingUtil.inflate(
//                 LayoutInflater.from(viewGroup.getContext()),
//                 R.layout.item_history_code,
//                 viewGroup,
//                 false
//         );
//         return new HistoryItemViewHolder(binding);
//     }
// 
//     @Override
//     public void onBindViewHolder(@NonNull HistoryItemViewHolder historyItemViewHolder, int i) {
//         ItemHistoryCodeBinding binding = historyItemViewHolder.binding;
//         HistoryItemViewModel viewModel = new HistoryItemViewModel(context, historyEntries.get(i));
//         binding.setViewModel(viewModel);
//         binding.itemView.setOnClickListener(viewModel.onClickItem());
//         binding.itemView.setOnLongClickListener(viewModel.onLongClickItem());
// 
//         Bitmap image = historyEntries.get(i).getImage();
//         if(image != null) {
//             Glide.with(context).load(image).placeholder(R.drawable.ic_no_image_accent_24dp).into(binding.itemHistoryImage);
//         } else {
//             Glide.with(context).load(R.drawable.ic_no_image_accent_24dp).into(binding.itemHistoryImage);
//         }
//     }
// 
//     @Override
//     public int getItemCount() {
//         return historyEntries.size();
//     }
// 
//     @Override
//     public long getItemId(int i) {
//         return historyEntries.get(i).get_id();
//     }
// 
//     public static class HistoryItemViewHolder extends RecyclerView.ViewHolder {
//         ItemHistoryCodeBinding binding;
// 
//         public HistoryItemViewHolder(@NonNull ItemHistoryCodeBinding binding) {
//             super(binding.itemView);
//             this.binding = binding;
//         }
//     }
// }
// 
// Path: app/src/main/java/com/secuso/privacyfriendlycodescanner/qrscanner/ui/viewmodel/HistoryViewModel.java
// public class HistoryViewModel extends AndroidViewModel {
// 
//     private final ExecutorService executorService = Executors.newSingleThreadExecutor();
// 
//     private final MediatorLiveData<List<HistoryItem>> historyItemsLiveData = new MediatorLiveData<>();
// 
//     public HistoryViewModel(@NonNull final Application application) {
//         super(application);
// 
//         loadHistories();
//     }
// 
//     public LiveData<List<HistoryItem>> getHistoryItems() {
//         return historyItemsLiveData;
//     }
// 
//     private void loadHistories() {
//         LiveData<List<HistoryItem>> historyEntries = AppRepository.getInstance(getApplication()).getHistoryEntriesLiveData();
//         historyItemsLiveData.addSource(historyEntries, historyItemsLiveData::setValue);
//     }
// }


// Path: app/src/main/java/com/secuso/privacyfriendlycodescanner/qrscanner/ui/activities/HistoryActivity.java
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.secuso.privacyfriendlycodescanner.qrscanner.R;
import com.secuso.privacyfriendlycodescanner.qrscanner.database.AppRepository;
import com.secuso.privacyfriendlycodescanner.qrscanner.ui.adapter.HistoryAdapter;
import com.secuso.privacyfriendlycodescanner.qrscanner.ui.viewmodel.HistoryViewModel;

package com.secuso.privacyfriendlycodescanner.qrscanner.ui.activities;




/**
 * History Overview that shows a list of scanned codes.
 *
 * @author Christopher Beckmann
 */
public class HistoryActivity extends AppCompatActivity {

    private HistoryAdapter mHistoryAdapter;
    private RecyclerView mHistoryRecyclerView;
    private HistoryViewModel mViewModel;