<file_sep>package com.book.storiek.Database;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.book.storiek.Model.Story;
import com.squareup.picasso.Picasso;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

public class Database extends SQLiteOpenHelper {
    Context context;

    public Database(Context context) {
        super(context, info_db.DATABASE_NAME, null, info_db.DATABASE_VERSION);
        this.context = context;
        isDatabase();
    }

    private void isDatabase() {

        File check = new File(info_db.PACKAGE);
        if (check.exists()) {

        } else {
            check.mkdir();
        }
        check = context.getDatabasePath(info_db.DATABASE_NAME);
        if (check.exists()) {

        } else {
            try {
                copyDataBase();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

    private void copyDataBase() throws IOException {

        InputStream myInput = context.getAssets().open(info_db.DATABASE_SOURCE);

        String outFileName = info_db.PACKAGE + info_db.DATABASE_NAME;

        OutputStream myOutput = new FileOutputStream(outFileName);

        byte[] buffer = new byte[1024];
        int length;
        while ((length = myInput.read(buffer)) > 0) {
            myOutput.write(buffer, 0, length);
        }

        myOutput.flush();
        myOutput.close();
        myInput.close();

    }

    public List<Story> getAllStory() {
        SQLiteDatabase db = this.getReadableDatabase();
        List<Story> data = new ArrayList<>();
        String query = "SELECT * FROM story";
        Cursor cursor = db.rawQuery(query, null);
        if (cursor.moveToFirst()) {
            do {
                Story story = new Story();
                story.setId(cursor.getInt(cursor.getColumnIndex(info_db.DATA_ID)));
                story.setCategory(cursor.getString(cursor.getColumnIndex(info_db.DATA_CATEGORY)));
                story.setName(cursor.getString(cursor.getColumnIndex(info_db.DATA_NAME)));
                story.setField(cursor.getString(cursor.getColumnIndex(info_db.DATA_FIELD)));
                story.setFav(cursor.getInt(cursor.getColumnIndex(info_db.DATA_FAV)));
                story.setImage(cursor.getString(cursor.getColumnIndex(info_db.DATA_IMAGE)));
                story.setDisc(cursor.getString(cursor.getColumnIndex(info_db.DATA_DISC)));
                data.add(story);
            }
            while (cursor.moveToNext());

        }
        cursor.close();
        db.close();
        return data;
    }

    public List<Story> getTanzStory() {
        SQLiteDatabase db = this.getReadableDatabase();
        List<Story> data = new ArrayList<>();
        String query = "SELECT * FROM story WHERE category='tanz'";
        Cursor cursor = db.rawQuery(query, null);
        if (cursor.moveToFirst()) {
            do {
                Story story = new Story();
                story.setId(cursor.getInt(cursor.getColumnIndex(info_db.DATA_ID)));
                story.setCategory(cursor.getString(cursor.getColumnIndex(info_db.DATA_CATEGORY)));
                story.setName(cursor.getString(cursor.getColumnIndex(info_db.DATA_NAME)));
                story.setField(cursor.getString(cursor.getColumnIndex(info_db.DATA_FIELD)));
                story.setFav(cursor.getInt(cursor.getColumnIndex(info_db.DATA_FAV)));
                story.setImage(cursor.getString(cursor.getColumnIndex(info_db.DATA_IMAGE)));
                story.setDisc(cursor.getString(cursor.getColumnIndex(info_db.DATA_DISC)));
                data.add(story);
            }
            while (cursor.moveToNext());

        }
        cursor.close();
        db.close();
        return data;
    }

    public List<Story> getMasalStory() {
        SQLiteDatabase db = this.getReadableDatabase();
        List<Story> data = new ArrayList<>();
        String query = "SELECT * FROM story WHERE category='masal'";
        Cursor cursor = db.rawQuery(query, null);
        if (cursor.moveToFirst()) {
            do {
                Story story = new Story();
                story.setId(cursor.getInt(cursor.getColumnIndex(info_db.DATA_ID)));
                story.setCategory(cursor.getString(cursor.getColumnIndex(info_db.DATA_CATEGORY)));
                story.setName(cursor.getString(cursor.getColumnIndex(info_db.DATA_NAME)));
                story.setField(cursor.getString(cursor.getColumnIndex(info_db.DATA_FIELD)));
                story.setFav(cursor.getInt(cursor.getColumnIndex(info_db.DATA_FAV)));
                story.setImage(cursor.getString(cursor.getColumnIndex(info_db.DATA_IMAGE)));
                story.setDisc(cursor.getString(cursor.getColumnIndex(info_db.DATA_DISC)));
                data.add(story);
            }
            while (cursor.moveToNext());

        }
        cursor.close();
        db.close();
        return data;
    }

    public List<Story> getDiniStory() {
        SQLiteDatabase db = this.getReadableDatabase();
        List<Story> data = new ArrayList<>();
        String query = "SELECT * FROM story WHERE category='dini'";
        Cursor cursor = db.rawQuery(query, null);
        if (cursor.moveToFirst()) {
            do {
                Story story = new Story();
                story.setId(cursor.getInt(cursor.getColumnIndex(info_db.DATA_ID)));
                story.setCategory(cursor.getString(cursor.getColumnIndex(info_db.DATA_CATEGORY)));
                story.setName(cursor.getString(cursor.getColumnIndex(info_db.DATA_NAME)));
                story.setField(cursor.getString(cursor.getColumnIndex(info_db.DATA_FIELD)));
                story.setFav(cursor.getInt(cursor.getColumnIndex(info_db.DATA_FAV)));
                story.setImage(cursor.getString(cursor.getColumnIndex(info_db.DATA_IMAGE)));
                story.setDisc(cursor.getString(cursor.getColumnIndex(info_db.DATA_DISC)));
                data.add(story);
            }
            while (cursor.moveToNext());

        }
        cursor.close();
        db.close();
        return data;

    }

    public List<Story> getFavStory() {
        SQLiteDatabase db = this.getReadableDatabase();
        List<Story> data = new ArrayList<>();
        String query = "SELECT * FROM story WHERE fav = 1";
        Cursor cursor = db.rawQuery(query, null);
        if (cursor.moveToFirst()) {
            do {
                Story story = new Story();
                story.setId(cursor.getInt(cursor.getColumnIndex(info_db.DATA_ID)));
                story.setCategory(cursor.getString(cursor.getColumnIndex(info_db.DATA_CATEGORY)));
                story.setName(cursor.getString(cursor.getColumnIndex(info_db.DATA_NAME)));
                story.setField(cursor.getString(cursor.getColumnIndex(info_db.DATA_FIELD)));
                story.setFav(cursor.getInt(cursor.getColumnIndex(info_db.DATA_FAV)));
                story.setImage(cursor.getString(cursor.getColumnIndex(info_db.DATA_IMAGE)));
                story.setDisc(cursor.getString(cursor.getColumnIndex(info_db.DATA_DISC)));
                data.add(story);
            }
            while (cursor.moveToNext());

        }
        cursor.close();
        db.close();
        return data;

    }

    public int fav_value(int id) {
        SQLiteDatabase db = this.getReadableDatabase();
        String query = "SELECT " + info_db.DATA_FAV + " FROM story WHERE " + info_db.DATA_ID + "=" + id + "";
        int value = 0;
        Cursor cursor = db.rawQuery(query, null);
        if (cursor.moveToFirst()) {
            value = cursor.getInt(cursor.getColumnIndex(info_db.DATA_FAV));
            do {
            } while (cursor.moveToNext());

        }
        db.close();
        return value;
    }

    public void fav(int status, int id) {
        SQLiteDatabase db = this.getReadableDatabase();
        String query = "UPDATE story SET " + info_db.DATA_FAV + "=" + status + " WHERE " + info_db.DATA_ID + "=" + id + "";
        db.execSQL(query);
        db.close();
    }


    @Override
    public void onCreate(SQLiteDatabase db) {

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }

}
<file_sep>package com.book.storiek;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.book.storiek.Adapter.StoryAdapter;
import com.book.storiek.Database.Database;
import com.book.storiek.Model.Story;

import java.util.List;

public class TanzFragment extends Fragment {
    View view;
    RecyclerView recyclerView;
    StoryAdapter adapter;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.recycler_main, container, false);
        setupViews();
        return view;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    private void setupViews() {
        recyclerView = view.findViewById(R.id.recycler_id);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        Database db = new Database(getActivity());
        List<Story> storyList = db.getTanzStory();
        adapter = new StoryAdapter(getActivity(), storyList);
        recyclerView.setAdapter(adapter);
    }
}
<file_sep>package com.book.storiek;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class RegisterActivity extends AppCompatActivity implements View.OnClickListener {

    EditText username, email;
    Button submit;
    boolean isLogin = false;
    private static final String LOGIN = "login";
    String username_txt, email_text;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        setupViews();
    }

    private void setupViews() {
        username = findViewById(R.id.Username);
        submit = findViewById(R.id.Submit);
        //email = findViewById(R.id.email);
        submit.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        int viewID = v.getId();
        switch (viewID) {
            case R.id.Submit:
                nameValidation();
                break;
        }
    }

    private void nameValidation() {
        username_txt = username.getText().toString().trim();
        //email_text = email.getText().toString().trim();
        //Boolean isEmail = email_text.contains("@gmail.com");
        if (username_txt.isEmpty()) {
            Toast.makeText(this, "نام کاربری خود را وارد کنید", Toast.LENGTH_SHORT).show();
        }
        /*else if (email_text.isEmpty()) {
            Toast.makeText(this, "ایمیل را وارد کنید", Toast.LENGTH_SHORT).show();
        } else if (isEmail == false) {
            Toast.makeText(this, "ایمیل معتبر نیست", Toast.LENGTH_SHORT).show();
        }*/
        else {
            saveUsername();
        }

    }

    private void saveUsername() {

        isLogin = !isLogin;
        SharedPreferences sharedPreferences = getSharedPreferences(LOGIN, MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("USERNAME", username_txt);
        //editor.putString("EMAIL", email_text);
        editor.putBoolean("ISLOGIN", isLogin);
        editor.apply();

        goToHome();

    }

    private void goToHome() {

        Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
        startActivity(intent);
        finish();
    }
}