Как добавить градиентный дизайн в карту с помощью панели администратора (Backend for App) - PullRequest
0 голосов
/ 03 марта 2019

У меня есть одно приложение Quotes, и оно также имеет панель администратора.

Проблема в том, что я могу добавить только один цвет с помощью панели администратора. Я хочу добавить цвет градиентас помощью панели администратора, как я могу это сделать.Я пытался добавить возможные детали, но если вы хотите больше подробностей, я предоставлю.Пожалуйста помоги!Я в замешательстве!

Screenshot of Quote card Layout

Screenshot of Admin Panel

Screenshot of Category table of Database


Вот моя база данных.Java

    package com.ReBirth.Statusly.data;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import com.ReBirth.Statusly.model.Quotes;
import java.util.ArrayList;
import java.util.List;


public class DatabaseHandler extends SQLiteOpenHelper {

    private Context context;
    private SQLiteDatabase db;

    private static final int DATABASE_VERSION       = 1;
    private static final String DATABASE_NAME       = "quotes_db";

    public static final String TABLE_FAVORITES      = "favorites";

    // Columns names TABLE_FAVORITES
    private static final String ID                = "id";
    private static final String CategoryID        = "cat_id";
    private static final String CategoryName      = "cat_name";
    private static final String CategoryImg       = "cat_img";
    private static final String CategoryColor     = "cat_color";
    private static final String Date              = "date";
    private static final String Body              = "body";

    public DatabaseHandler(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        this.context=context;
        this.db = this.getWritableDatabase();
        Log.d("DB", "Constructor");
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        Log.d("DB", "onCreate");
        createTableFavorites(db);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int i, int i1) {
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_FAVORITES);
        createTableFavorites(db);
    }

    private void createTableFavorites(SQLiteDatabase db) {
        String CREATE_TABLE = "CREATE TABLE " + TABLE_FAVORITES + "("
                + ID + " INTEGER PRIMARY KEY, "
                + CategoryID + " INTEGER, "
                + CategoryName + " TEXT, "
                + CategoryImg + " TEXT, "
                + CategoryColor + " TEXT, "
                + Date + " TEXT, "
                + Body + " TEXT "
                + ")";
        db.execSQL(CREATE_TABLE);
    }

//////////////////////////////////////////////////////// Favorites ////////////////////////////////////////////////////////

    public Quotes addOneFavorite(Quotes quotes) {
        ContentValues values = new ContentValues();
        values.put(ID, quotes.getId());
        values.put(CategoryID, quotes.getCat_id());
        values.put(CategoryName, quotes.getCat_name());
        values.put(CategoryImg, quotes.getCat_img());
        values.put(CategoryColor, quotes.getCat_color());
        values.put(Date, quotes.getDate());
        values.put(Body, quotes.getBody());
        db.insert(TABLE_FAVORITES, null, values);
        return quotes;
    }

    public void deleteFavorites(Quotes quotes) {
        db.delete(TABLE_FAVORITES, ID + " = ?", new String[] { String.valueOf(quotes.getId()+"") });
    }

    public boolean isFavoritesExist(Integer id) {
        Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_FAVORITES + " WHERE " + ID + " = ?", new String[]{id+""});
        int count = cursor.getCount();
        cursor.close();
        return (count>0);
    }

    public List<Quotes> getAllFavorites() {
        return getAll(TABLE_FAVORITES);
    }

    private List<Quotes> getAll(String table) {
        List<Quotes> list;
        Cursor cursor = db.rawQuery("SELECT * FROM " + table + " ORDER BY " + ID + " DESC", null);
        list = getAllFormCursor(cursor);
        return list;
    }

    private List<Quotes> getAllFormCursor(Cursor cursor) {
        List<Quotes> list = new ArrayList<>();
        if (cursor.moveToFirst()) {
            do {
                Quotes r = new Quotes();
                r.setId(cursor.getInt(cursor.getColumnIndex(ID)));
                r.setCat_id(cursor.getInt(cursor.getColumnIndex(CategoryID)));
                r.setCat_name(cursor.getString(cursor.getColumnIndex(CategoryName)));
                r.setCat_img(cursor.getString(cursor.getColumnIndex(CategoryImg)));
                r.setCat_color(cursor.getString(cursor.getColumnIndex(CategoryColor)));
                r.setDate(cursor.getString(cursor.getColumnIndex(Date)));
                r.setBody(cursor.getString(cursor.getColumnIndex(Body)));
                list.add(r);
            } while (cursor.moveToNext());
        }
        return list;
    }

}

приведенный ниже код используется для добавления цвета фона (Код из QuoteAdapter.java)

public void onBindViewHolder(@NonNull final ViewHolder viewHolder, final int position) {

        final Quotes quotes = data.get(position);

        viewHolder.quote.setText(quotes.getBody());

        viewHolder.views.setText(mContext.getResources().getString(R.string.views) +" "+ quotes.getViews());
        viewHolder.date.setText(Tools.DateToTimeFormat(quotes.getDate()));
        viewHolder.card.setBackgroundColor(Color.parseColor(quotes.getCat_color()));

Файл модели (Quotes.java)

package com.ReBirth.Statusly.model;

import com.google.gson.annotations.SerializedName;

import java.io.Serializable;

public class Quotes implements Serializable {

    @SerializedName("id")
    private Integer id;
    @SerializedName("cat_id")
    private Integer cat_id;
    @SerializedName("cat_name")
    private String cat_name;
    @SerializedName("cat_img")
    private String cat_img;
    @SerializedName("cat_color")
    private String cat_color;
    @SerializedName("body")
    private String body;
    @SerializedName("date")
    private String date;
    @SerializedName("views")
    private String views;

    public Integer getId() {
        return id;
    }

    public Integer getCat_id() {
        return cat_id;
    }

    public String getCat_name() {
        return cat_name;
    }

    public String getCat_img() {
        return cat_img;
    }

    public String getCat_color() {
        return cat_color;
    }

    public String getBody() {
        return body;
    }

    public String getDate() {
        return date;
    }

    public String getViews() {
        return views;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public void setCat_id(Integer cat_id) {
        this.cat_id = cat_id;
    }

    public void setCat_name(String cat_name) {
        this.cat_name = cat_name;
    }

    public void setCat_img(String cat_img) {
        this.cat_img = cat_img;
    }

    public void setCat_color(String cat_color) {
        this.cat_color = cat_color;
    }

    public void setBody(String body) {
        this.body = body;
    }

    public void setDate(String date) {
        this.date = date;
    }

}

ниже Я дал php-файл панели администратора, который используется для ввода цвета

<?php include("files/header.php"); ?>
<?php include_once 'helpers/Upimg.php'; ?>



<link href="assets/css/colorpicker.css" rel="stylesheet"/>


<div class="row">
    <div class="col-md-12">

        <div class="panel panel-default panel-table">

            <div class="panel-heading">
                <div class="row">
                    <div class="col col-xs-6">
                        <h6 class="title"><strong>Add Category :</strong></h6>
                    </div>
                    <div class="col col-xs-6 text-right">
                        <img style="width: 40px; height:40px" id='img-upload'"/>
                    </div>
                </div>
            </div>

            <form action="add_category.php" class="form" method="post" enctype="multipart/form-data">
                <div class="panel-body">
                    <?php
                    if (isset($_POST['save'])) {
                        $name = $Fun->post($Fun->clears($_POST['name']));
                        $color = $Fun->post($Fun->clears($_POST['color']));
                        $img_name = 'category_' . time();
                        list($msg, $result) = up_file($_FILES['img'], $img_name);
                        if ($msg == 'succ') {
                            $img = $result;
                        } else {
                            echo $result;
                        }
                        if (empty($_FILES["img"]["name"])) {
                            $Fun->alert_msg("Image is empty", "danger");
                        } else {
                            $insert = $db->Insert("`category`", "(`name`,`image`,`color`)", "('$name','$img','$color')") or die($db->Error(__file__, __line__));
                            if (isset($insert)) {
                                $Fun->alert_msg("Added successfully", "success");
                                $Fun->refresh("2", "add_category.php");
                            }
                        }
                    }
                    ?>

                    <div class="row">
                        <div class="col-md-5">
                            <div class="form-group">
                                <label>Category Name :</label>
                                <input type="text" class="form-control border-input" name="name" value="<?= $_POST['name'] ?>" required>
                            </div>
                        </div>

                        <div class="col-md-2">
                            <div class="form-group">
                                <div class="form-group">
                                    <label>Color :</label>
                                    <input type="text" autocomplete="off" class="form-control border-input" id="ColorPicker" name="color" value="<?= $_POST['color'] ?>" required>
                                </div>
                            </div>
                        </div>

                        <div class="col-md-5">
                            <div class="form-group">
                                <label>Select Icon : <strong class="icon-danger">(Recommended resolution: 128x128)</strong></label>
                                <div class="input-group">
                                    <span class="input-group-btn">
                                         <span class="btn btn-default btn-file">Browse<input type="file" name="img" id="imgInp"></span>
                                    </span>
                                    <input type="text" class="form-control" readonly>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>

                <div class="panel-footer">
                    <div class="row">
                        <div class="text-center">
                            <button type="submit" class="btn btn-success btn-fill" name="save">Save</button>
                        </div>
                    </div>
                </div>

            </form>

        </div>

    </div>
</div>

<?php include("files/footer.php"); ?>
...