<commit_before>package fr.free.nrw.commons.nearby;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;

import fr.free.nrw.commons.R;
import fr.free.nrw.commons.contributions.ContributionController;
import timber.log.Timber;

import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;

class DirectUpload {

    private String title;
    private String desc;
    private ContributionController controller;

    DirectUpload(String title, String desc, Fragment fragment) {
        this.title = title;
        this.desc = desc;
        controller = new ContributionController(fragment);
    }

    void storeSharedPrefs(Context context) {

        Activity activity = (Activity) context;
        SharedPreferences sharedPref = activity.getPreferences(Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPref.edit();

        editor.putString("Title", title);
        editor.putString("Desc", desc);
        editor.apply();

        //TODO: Shift this into title/desc screen after upload initiated
        sharedPref = activity.getPreferences(Context.MODE_PRIVATE);
        String imageTitle = sharedPref.getString("Title", "");
        String imageDesc = sharedPref.getString("Desc", "");

        Timber.d("After shared prefs, image title: " + imageTitle + " Image desc: " + imageDesc);
    }

    void initiateGalleryUpload(Context context) {
        Activity activity = (Activity) context;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (ContextCompat.checkSelfPermission(activity, READ_EXTERNAL_STORAGE) != PERMISSION_GRANTED) {
                if (activity.shouldShowRequestPermissionRationale(READ_EXTERNAL_STORAGE)) {
                    new AlertDialog.Builder(activity)
                            .setMessage(activity.getString(R.string.read_storage_permission_rationale))
                            .setPositiveButton("OK", (dialog, which) -> {
                                activity.requestPermissions(new String[]{READ_EXTERNAL_STORAGE}, 1);
                                dialog.dismiss();
                            })
                            .setNegativeButton("Cancel", null)
                            .create()
                            .show();
                } else {
                    activity.requestPermissions(new String[]{READ_EXTERNAL_STORAGE},
                            1);
                }
            } else {
                controller.startGalleryPick();
            }
        }
        else {
            controller.startGalleryPick();
        }
    }
}<commit_msg>Save fragment as instance variable<commit_after>package fr.free.nrw.commons.nearby;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;

import fr.free.nrw.commons.R;
import fr.free.nrw.commons.contributions.ContributionController;
import timber.log.Timber;

import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;

class DirectUpload {

    private String title;
    private String desc;
    private ContributionController controller;
    private Fragment fragment;

    DirectUpload(String title, String desc, Fragment fragment) {
        this.title = title;
        this.desc = desc;
        this.fragment = fragment;
        controller = new ContributionController(fragment);
    }

    void storeSharedPrefs() {
        SharedPreferences sharedPref = fragment.getActivity().getPreferences(Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPref.edit();

        editor.putString("Title", title);
        editor.putString("Desc", desc);
        editor.apply();

        //TODO: Shift this into title/desc screen after upload initiated
        sharedPref = fragment.getActivity().getPreferences(Context.MODE_PRIVATE);
        String imageTitle = sharedPref.getString("Title", "");
        String imageDesc = sharedPref.getString("Desc", "");

        Timber.d("After shared prefs, image title: " + imageTitle + " Image desc: " + imageDesc);
    }

    void initiateGalleryUpload(Context context) {
        Activity activity = (Activity) context;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (ContextCompat.checkSelfPermission(activity, READ_EXTERNAL_STORAGE) != PERMISSION_GRANTED) {
                if (activity.shouldShowRequestPermissionRationale(READ_EXTERNAL_STORAGE)) {
                    new AlertDialog.Builder(activity)
                            .setMessage(activity.getString(R.string.read_storage_permission_rationale))
                            .setPositiveButton("OK", (dialog, which) -> {
                                activity.requestPermissions(new String[]{READ_EXTERNAL_STORAGE}, 1);
                                dialog.dismiss();
                            })
                            .setNegativeButton("Cancel", null)
                            .create()
                            .show();
                } else {
                    activity.requestPermissions(new String[]{READ_EXTERNAL_STORAGE},
                            1);
                }
            } else {
                controller.startGalleryPick();
            }
        }
        else {
            controller.startGalleryPick();
        }
    }


//TODO: Handle onRequestPermissionsResult
}
{'fraction_non_alphanumeric': 0.09451219512195122, 'fraction_numerical': 0.0016937669376693768, 'mean_word_length': 2.3361581920903953, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '14261', 'n_tokens_mistral': 1529, 'n_tokens_neox': 1480, 'n_words': 281}