Italian Conversione Applicazione

Schakalaka

Active Member
Licensed User
Longtime User
Ciao gente,
vorrei "convertire un' app scritta con android studio in b4a.
è un' app per condividere wallpapers e viene gestita da un backend in php attraverso json.

potete trovare l' app qui:

https://drive.google.com/file/d/1uzD4vpeJ1iRg32bBIk3MQPZyrIXtZCYl/view?usp=sharing

codice php
B4X:
https://pastebin.com/9rj9x1hK


se vi serve altro, fatemi sapere...
Vorrei qualche dritta su come procedere.

grazie
 
Last edited:

Schakalaka

Active Member
Licensed User
Longtime User
Fatto!
il mio livello di b4a, non mi permette di "tradurre" da android studio
 

Star-Dust

Expert
Licensed User
Longtime User
Fatto!
il mio livello di b4a, non mi permette di "tradurre" da android studio
Quindi stai chiedendo un corso di formazione per sviluppatori di B4A?

Mi spiace il termine delle iscrizioni era 1° aprile 2019. Prova al prossimo semestre :p:p
 

Schakalaka

Active Member
Licensed User
Longtime User
Mah, io ho già seguito un corso di b4a base.. che mi ha permesso di creare questa app:

https://play.google.com/store/apps/details?id=eu.beraldogiuliano.worldcapitls

Ho provato anche a fare un corso di android studio, ma non ci ho capito molto..

Magri se qualcuno conosce bene entrambi i linguaggi, e magari ha già fatto applicazioni simili (a livello di codice), può indicarmi come fare

Non lo faccio a livello professionale. Son più interessato a capire come fare, che chiedere che venga fatto per me..
 

Star-Dust

Expert
Licensed User
Longtime User
Non lo faccio a livello professionale. Son più interessato a capire come fare, che chiedere che venga fatto per me..
Ottimo mi sei già simpatico.

Cosa fa quest'applicazione? Cosa vorresti ottenere? L'app Android Studio come si collega con PHP ?
Così ti possiamo dare indicazioni. Butta giù l'interfaccia così c'è una base da cui partire.
 
Last edited:

Schakalaka

Active Member
Licensed User
Longtime User
questa applicazione è per condividere wallpapers ma la stessa dinamica può esser utilizzata anche per altri scopi.
Si collega al backend tramite okhttpPost e JSON parser
crea un db locale .db ma dove vengono caricati i dati è quello online (SQLiteDatabase)
Oltre alle immagini, carica anche altre info: email, versione, nome sviluppatore.. che possono essere aggiornate direttamente dal sito.
Ho allegato il file completo. queste info le trovi nella cartella "util" "DBHELPER".
L' url del server di riferimento, è stato inserito nel file gradle.properties.
Provo a fare un' interfaccia semplice, per cominciare con pochi dati.
Se serve aggiungo anche i file php
grazie
.
 

Star-Dust

Expert
Licensed User
Longtime User
Quindi dall'app ricevi (e forse anche invii) wallpaper.
Associato a ogni wallpaper hai diversi campi (autore, dimensioni ecc..)
Dal PHP ricevi la lista in formato JSON e il download lo fai con http.

Ho capito bene?
 

Schakalaka

Active Member
Licensed User
Longtime User
si, ho 4 campi, categoria, Formato, Il percorso dell' immagine, e i vari tag.

Prendo dal server anche altri dati, come le chiavi admob, le policy privacy, il logo...
a questo punto via qui direttamente:
B4X:
http://eliteandroidapp.netsons.org/php_web_services/

Va bene anche un "pezzo" alla volta. Credo che una volta capito il meccanismo ci si può sbizzarrire di fantasia..

Questo è il Db completo:
B4X:
-- phpMyAdmin SQL Dump
-- version 4.8.0.1
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Jan 18, 2019 at 05:10 AM
-- Server version: 10.1.32-MariaDB
-- PHP Version: 7.2.5
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `hd_wallpaper_new_final`
--
-- --------------------------------------------------------
--
-- Table structure for table `tbl_admin`
--
CREATE TABLE `tbl_admin` (
  `id` int(11) NOT NULL,
  `username` varchar(100) NOT NULL,
  `password` varchar(100) NOT NULL,
  `email` varchar(200) NOT NULL,
  `image` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dumping data for table `tbl_admin`
--
INSERT INTO `tbl_admin` (`id`, `username`, `password`, `email`, `image`) VALUES
(1, 'admin', 'admin', 'viaviwebtech@gmail.com', 'profile.png');
-- --------------------------------------------------------
--
-- Table structure for table `tbl_category`
--
CREATE TABLE `tbl_category` (
  `cid` int(11) NOT NULL,
  `category_name` varchar(255) NOT NULL,
  `category_image` varchar(255) NOT NULL,
  `status` int(1) NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dumping data for table `tbl_category`
--
INSERT INTO `tbl_category` (`cid`, `category_name`, `category_image`, `status`) VALUES
(1, 'Abstract', '66832_Abstract_Category_400_200.jpg', 1),
(2, 'Baby', '8312_beby_category_1_400_200.jpg', 1),
(3, 'Bike', '49067_Bike_Category_400_200.jpg', 1),
(4, 'Bird', '38144_Bird.jpg', 1),
(5, 'Car', '177_Car_Category_400_200.jpg', 1),
(6, 'Celebrities', '66450_fashion_1.jpg', 1),
(7, 'Love', '93863_Love_Category1_400_200.jpg', 1),
(8, 'Nature', '99528_nature.jpg', 1);
-- --------------------------------------------------------
--
-- Table structure for table `tbl_home_banner`
--
CREATE TABLE `tbl_home_banner` (
  `id` int(11) NOT NULL,
  `banner_name` varchar(255) NOT NULL,
  `banner_image` varchar(255) NOT NULL,
  `banner_url` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Table structure for table `tbl_rating`
--
CREATE TABLE `tbl_rating` (
  `id` int(11) NOT NULL,
  `post_id` int(11) NOT NULL,
  `user_id` varchar(255) NOT NULL,
  `ip` varchar(255) NOT NULL,
  `rate` int(11) NOT NULL,
  `dt_rate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Table structure for table `tbl_rating_gif`
--
CREATE TABLE `tbl_rating_gif` (
  `id` int(11) NOT NULL,
  `post_id` int(11) NOT NULL,
  `user_id` varchar(255) NOT NULL,
  `ip` varchar(255) NOT NULL,
  `rate` int(11) NOT NULL,
  `dt_rate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Table structure for table `tbl_settings`
--
CREATE TABLE `tbl_settings` (
  `id` int(11) NOT NULL,
  `onesignal_app_id` text NOT NULL,
  `onesignal_rest_key` text NOT NULL,
  `app_api_key` varchar(255) NOT NULL,
  `app_name` varchar(255) NOT NULL,
  `app_logo` varchar(255) NOT NULL,
  `app_email` varchar(255) NOT NULL,
  `app_version` varchar(255) NOT NULL,
  `app_author` varchar(255) NOT NULL,
  `app_contact` varchar(255) NOT NULL,
  `app_website` varchar(255) NOT NULL,
  `app_description` text NOT NULL,
  `app_developed_by` varchar(255) NOT NULL,
  `app_privacy_policy` text NOT NULL,
  `gif_on_off` varchar(255) NOT NULL DEFAULT 'true',
  `home_latest_limit` int(2) NOT NULL DEFAULT '10',
  `home_most_viewed_limit` int(2) NOT NULL DEFAULT '10',
  `home_most_rated_limit` int(2) NOT NULL DEFAULT '10',
  `home_portrait_limit` int(2) NOT NULL DEFAULT '10',
  `home_landscape_limit` int(2) NOT NULL DEFAULT '10',
  `home_square_limit` int(2) NOT NULL DEFAULT '10',
  `api_latest_limit` int(3) NOT NULL DEFAULT '15',
  `api_cat_order_by` varchar(255) NOT NULL DEFAULT 'category_name',
  `api_cat_post_order_by` varchar(255) NOT NULL DEFAULT 'DESC',
  `api_gif_post_order_by` varchar(255) NOT NULL DEFAULT 'DESC',
  `publisher_id` text NOT NULL,
  `interstital_ad` varchar(255) NOT NULL,
  `interstital_ad_id` varchar(255) NOT NULL,
  `interstital_ad_click` varchar(255) NOT NULL,
  `banner_ad` varchar(255) NOT NULL,
  `banner_ad_id` varchar(255) NOT NULL,
  `publisher_id_ios` varchar(500) NOT NULL,
  `app_id_ios` varchar(500) NOT NULL,
  `interstital_ad_ios` varchar(500) NOT NULL,
  `interstital_ad_id_ios` varchar(500) NOT NULL,
  `interstital_ad_click_ios` varchar(500) NOT NULL,
  `banner_ad_ios` varchar(500) NOT NULL,
  `banner_ad_id_ios` varchar(500) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dumping data for table `tbl_settings`
--
INSERT INTO `tbl_settings` (`id`, `onesignal_app_id`, `onesignal_rest_key`, `app_api_key`, `app_name`, `app_logo`, `app_email`, `app_version`, `app_author`, `app_contact`, `app_website`, `app_description`, `app_developed_by`, `app_privacy_policy`, `gif_on_off`, `home_latest_limit`, `home_most_viewed_limit`, `home_most_rated_limit`, `home_portrait_limit`, `home_landscape_limit`, `home_square_limit`, `api_latest_limit`, `api_cat_order_by`, `api_cat_post_order_by`, `api_gif_post_order_by`, `publisher_id`, `interstital_ad`, `interstital_ad_id`, `interstital_ad_click`, `banner_ad`, `banner_ad_id`, `publisher_id_ios`, `app_id_ios`, `interstital_ad_ios`, `interstital_ad_id_ios`, `interstital_ad_click_ios`, `banner_ad_ios`, `banner_ad_id_ios`) VALUES
(1, '', '', 'YtmpgwcUzCbeh1JlsK0gR0njtXm9g9lAUt4pzsPZhsH8a', 'HD Wallpaper App', 'Icon144.png', 'info@viaviweb.com', '1.0.0', 'Viavi Webtech', '+91 9227777522', 'www.viaviweb.com', '<p><strong>&ldquo;HD Wallpaper&rdquo;</strong> is a cool new app that brings all the best HD wallpapers and backgrounds to your Android device.</p>\r\n\r\n<p>Each high resolution image has been perfectly formatted fit to the phone display and comes with a host of user friendly features. The stunning UI allows you easily tap and swipe your way through the multiple image galleries. To develop similar app with your name you can contact us via skype or whatsapp.<br />\r\n<br />\r\n<strong>Skype:</strong> viaviwebtech<br />\r\n<strong>WhatsApp:</strong> +919227777522</p>\r\n', 'Viavi Webtech', '<p><strong>We are committed to protecting your privacy</strong></p>\r\n\r\n<p>We collect the minimum amount of information about you that is commensurate with providing you with a satisfactory service. This policy indicates the type of processes that may result in data being collected about you. Your use of this website gives us the right to collect that information.&nbsp;</p>\r\n\r\n<p><strong>Information Collected</strong></p>\r\n\r\n<p>We may collect any or all of the information that you give us depending on the type of transaction you enter into, including your name, address, telephone number, and email address, together with data about your use of the website. Other information that may be needed from time to time to process a request may also be collected as indicated on the website.</p>\r\n\r\n<p><strong>Information Use</strong></p>\r\n\r\n<p>We use the information collected primarily to process the task for which you visited the website. Data collected in the UK is held in accordance with the Data Protection Act. All reasonable precautions are taken to prevent unauthorised access to this information. This safeguard may require you to provide additional forms of identity should you wish to obtain information about your account details.</p>\r\n\r\n<p><strong>Cookies</strong></p>\r\n\r\n<p>Your Internet browser has the in-built facility for storing small files - &quot;cookies&quot; - that hold information which allows a website to recognise your account. Our website takes advantage of this facility to enhance your experience. You have the ability to prevent your computer from accepting cookies but, if you do, certain functionality on the website may be impaired.</p>\r\n\r\n<p><strong>Disclosing Information</strong></p>\r\n\r\n<p>We do not disclose any personal information obtained about you from this website to third parties unless you permit us to do so by ticking the relevant boxes in registration or competition forms. We may also use the information to keep in contact with you and inform you of developments associated with us. You will be given the opportunity to remove yourself from any mailing list or similar device. If at any time in the future we should wish to disclose information collected on this website to any third party, it would only be with your knowledge and consent.&nbsp;</p>\r\n\r\n<p>We may from time to time provide information of a general nature to third parties - for example, the number of individuals visiting our website or completing a registration form, but we will not use any information that could identify those individuals.&nbsp;</p>\r\n\r\n<p>In addition Dummy may work with third parties for the purpose of delivering targeted behavioural advertising to the Dummy website. Through the use of cookies, anonymous information about your use of our websites and other websites will be used to provide more relevant adverts about goods and services of interest to you. For more information on online behavioural advertising and about how to turn this feature off, please visit youronlinechoices.com/opt-out.</p>\r\n\r\n<p><strong>Changes to this Policy</strong></p>\r\n\r\n<p>Any changes to our Privacy Policy will be placed here and will supersede this version of our policy. We will take reasonable steps to draw your attention to any changes in our policy. However, to be on the safe side, we suggest that you read this document each time you use the website to ensure that it still meets with your approval.</p>\r\n\r\n<p><strong>Contacting Us</strong></p>\r\n\r\n<p>If you have any questions about our Privacy Policy, or if you want to know what information we have collected about you, please email us at hd@dummy.com. You can also correct any factual errors in that information or require us to remove your details form any list under our control.</p>\r\n', 'true', 20, 20, 20, 10, 10, 10, 20, 'category_name', 'DESC', 'ASC', 'pub-8356404931736973', 'true', 'ca-app-pub-3940256099942544/1033173712', '5', 'true', 'ca-app-pub-3940256099942544/6300978111', 'pub-8356404931736973', 'ca-app-pub-8356404931736973~5938963872', 'true', 'ca-app-pub-8356404931736973/9495065509', '5', 'true', 'ca-app-pub-8356404931736973/7383907483');
-- --------------------------------------------------------
--
-- Table structure for table `tbl_wallpaper`
--
CREATE TABLE `tbl_wallpaper` (
  `id` int(11) NOT NULL,
  `featured` int(1) NOT NULL DEFAULT '0',
  `cat_id` int(11) NOT NULL,
  `wallpaper_type` varchar(255) NOT NULL DEFAULT 'none',
  `image_date` date NOT NULL,
  `image` varchar(255) NOT NULL,
  `wall_tags` text NOT NULL,
  `total_rate` int(11) NOT NULL DEFAULT '0',
  `rate_avg` decimal(11,0) DEFAULT '0',
  `total_views` int(11) NOT NULL DEFAULT '0',
  `total_download` int(11) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dumping data for table `tbl_wallpaper`
--
INSERT INTO `tbl_wallpaper` (`id`, `featured`, `cat_id`, `wallpaper_type`, `image_date`, `image`, `wall_tags`, `total_rate`, `rate_avg`, `total_views`, `total_download`) VALUES
(1, 0, 4, 'Landscape', '2019-01-18', '6609_54559_Bird_landscap_6.jpg', 'Bird, Landscape ', 0, '0', 0, 0),
(2, 0, 1, 'Landscape', '2019-01-18', '49406_7419_Abstract_11.jpg', 'Abstract', 0, '0', 0, 0),
(3, 0, 2, 'Landscape', '2019-01-18', '45306_2_Baby_13.jpg', 'Baby,girl', 0, '0', 0, 0),
(4, 0, 3, 'Portrait', '2019-01-18', '27498_10101_Bike_6.jpg', 'bike,race', 0, '0', 0, 0),
(5, 0, 3, 'Landscape', '2019-01-18', '34109_16372_Bike_18.jpg', 'bike, Landscape,girl', 0, '0', 0, 0),
(6, 0, 6, 'Landscape', '2019-01-18', '2048_59621_Celebrities_1.jpg', 'beauty,fashion', 0, '0', 0, 0),
(7, 0, 6, 'Square', '2019-01-18', '4248_34560_fashion_1.jpg', 'beauty,fashion', 0, '0', 0, 0),
(8, 0, 7, 'Portrait', '2019-01-18', '71599_4842_Love_16.jpg', 'love', 0, '0', 0, 0);
-- --------------------------------------------------------
--
-- Table structure for table `tbl_wallpaper_gif`
--
CREATE TABLE `tbl_wallpaper_gif` (
  `id` int(11) NOT NULL,
  `image` varchar(255) NOT NULL,
  `gif_tags` text NOT NULL,
  `total_views` int(11) NOT NULL DEFAULT '0',
  `total_rate` int(11) NOT NULL DEFAULT '0',
  `rate_avg` decimal(11,2) NOT NULL DEFAULT '0.00',
  `total_download` int(11) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dumping data for table `tbl_wallpaper_gif`
--
INSERT INTO `tbl_wallpaper_gif` (`id`, `image`, `gif_tags`, `total_views`, `total_rate`, `rate_avg`, `total_download`) VALUES
(1, '17670_4.gif', 'cartoon', 90, 0, '0.00', 4);
--
-- Indexes for dumped tables
--
--
-- Indexes for table `tbl_admin`
--
ALTER TABLE `tbl_admin`
  ADD PRIMARY KEY (`id`);
--
-- Indexes for table `tbl_category`
--
ALTER TABLE `tbl_category`
  ADD PRIMARY KEY (`cid`);
--
-- Indexes for table `tbl_home_banner`
--
ALTER TABLE `tbl_home_banner`
  ADD PRIMARY KEY (`id`);
--
-- Indexes for table `tbl_rating`
--
ALTER TABLE `tbl_rating`
  ADD PRIMARY KEY (`id`);
--
-- Indexes for table `tbl_rating_gif`
--
ALTER TABLE `tbl_rating_gif`
  ADD PRIMARY KEY (`id`);
--
-- Indexes for table `tbl_settings`
--
ALTER TABLE `tbl_settings`
  ADD PRIMARY KEY (`id`);
--
-- Indexes for table `tbl_wallpaper`
--
ALTER TABLE `tbl_wallpaper`
  ADD PRIMARY KEY (`id`);
--
-- Indexes for table `tbl_wallpaper_gif`
--
ALTER TABLE `tbl_wallpaper_gif`
  ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `tbl_admin`
--
ALTER TABLE `tbl_admin`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
--
-- AUTO_INCREMENT for table `tbl_category`
--
ALTER TABLE `tbl_category`
  MODIFY `cid` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=34;
--
-- AUTO_INCREMENT for table `tbl_home_banner`
--
ALTER TABLE `tbl_home_banner`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `tbl_rating`
--
ALTER TABLE `tbl_rating`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `tbl_rating_gif`
--
ALTER TABLE `tbl_rating_gif`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `tbl_settings`
--
ALTER TABLE `tbl_settings`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
--
-- AUTO_INCREMENT for table `tbl_wallpaper`
--
ALTER TABLE `tbl_wallpaper`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9;
--
-- AUTO_INCREMENT for table `tbl_wallpaper_gif`
--
ALTER TABLE `tbl_wallpaper_gif`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=11;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
 

Schakalaka

Active Member
Licensed User
Longtime User
L' applicazione di collega ad un file API in php che genera la string json relativa.
Utilizza anche un db locale, ma non capisco quali dati vengono memorizzati.
Questo dovrebbe essere, ma senza server b4j
B4X:
https://www.b4x.com/android/forum/threads/b4x-cloudkvs-synchronized-key-value-store.63536/#content

ma non so come implementarlo.

ho anche provato a creare un' interfaccia di prova integrando Xcustomview, ma ho qualche problema per le immagini che sono "string" e non "bitmap".

Il prossimo passo è "tradurre" anche letteralmente questo:
B4X:
package com.vpapps.utils;

import android.annotation.SuppressLint;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import com.vpapps.items.ItemAbout;
import com.vpapps.items.ItemCat;
import com.vpapps.items.ItemGIF;
import com.vpapps.items.ItemWallpaper;

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

public class DBHelper extends SQLiteOpenHelper {

    private static String DB_FAKE_NAME = "wall.db";
    private static String DB_NAME = "wallpaper.db";
    private SQLiteDatabase db;
    private final Context context;
    private String DB_PATH;

    public DBHelper(Context context) {
        super(context, DB_FAKE_NAME, null, 4);
        this.context = context;
//        DB_PATH = "/data/data/" + context.getPackageName() + "/" + "databases/";
        DB_PATH = getReadableDatabase().getPath().substring(0,(getReadableDatabase().getPath().length()-DB_FAKE_NAME.length()));
    }

    public void createDataBase() throws IOException {

        boolean dbExist = checkDataBase();
        if (!dbExist) {
            getWritableDatabase();
            copyDataBase();
        } else {
            this.getWritableDatabase();
        }
    }

    private boolean checkDataBase() {
        File dbFile = new File(DB_PATH + DB_NAME);
        return dbFile.exists();
    }

    private void copyDataBase() throws IOException {

        InputStream myInput = context.getAssets().open(DB_FAKE_NAME);
        String outFileName = DB_PATH + DB_NAME;
        OutputStream myOutput = new FileOutputStream(outFileName);
        byte[] buffer = new byte[1024];
        int length;
        while ((length = myInput.read(buffer)) > 0) {
            myOutput.write(buffer, 0, length);
        }

        // Close the streams
        myOutput.flush();
        myOutput.close();
        myInput.close();
    }

    private Cursor getData(String Query) {
        String myPath = DB_PATH + DB_NAME;
        Cursor c = null;
        try {
            db = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
            c = db.rawQuery(Query, null);
        } catch (Exception e) {
            Log.e("Err", e.toString());
        }
        return c;
    }

    //UPDATE temp_dquot SET age='20',name1='--',rdt='11/08/2014',basic_sa='100000',plno='814',pterm='20',mterm='20',mat_date='11/08/2034',mode='YLY',dab_sa='100000',tr_sa='0',cir_sa='',bonus_rate='42',prem='5276',basic_prem='5118',dab_prem='100.0',step_rate='for Life',loyal_rate='0',bonus_rate='42',act_mat='1,88,000',mly_b_pr='448',qly_b_pr='1345',hly_b_pr='2664',yly_b_pr='5276'  WHERE uniqid=1
    private void dml(String Query) {
        String myPath = DB_PATH + DB_NAME;
        if (db == null)
            db = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
        try {
            db.execSQL(Query);
        } catch (Exception e) {
            Log.e("Error", e.toString());
        }
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
    }

    public ArrayList<ItemWallpaper> getWallpapers(String table, String typeee, String wallType) {
        ArrayList<ItemWallpaper> arrayList = new ArrayList<>();

        if(wallType.equals("")) {
            wallType = "'";
        } else {
            wallType = "' where type='" + wallType+"'";
        }

        String query = "";
        switch (typeee) {
            case "":
                query = "select * from '" + table + wallType;
                break;
            case "views":
                query = "select * from '" + table + "' order by views + 0 desc" +  wallType;
                break;
            case "rate":
                query = "select * from '" + table + "' order by avg_rate + 0 desc" + wallType;
                break;
        }
        Cursor cursor = getData(query);
        if (cursor != null && cursor.getCount() > 0) {
            cursor.moveToFirst();
            for (int i = 0; i < cursor.getCount(); i++) {
                String pid = cursor.getString(cursor.getColumnIndex("pid"));
                String cid = cursor.getString(cursor.getColumnIndex("cid"));
                String cname = cursor.getString(cursor.getColumnIndex("cname"));
                String img = cursor.getString(cursor.getColumnIndex("img"));
                String img_thumb = cursor.getString(cursor.getColumnIndex("img_thumb"));
                String views = cursor.getString(cursor.getColumnIndex("views"));
                String totalrate = cursor.getString(cursor.getColumnIndex("total_rate"));
                String averagerate = cursor.getString(cursor.getColumnIndex("avg_rate"));
                String download = cursor.getString(cursor.getColumnIndex("total_download"));
                String tags = cursor.getString(cursor.getColumnIndex("tags"));
                String type = cursor.getString(cursor.getColumnIndex("type"));
                String res = cursor.getString(cursor.getColumnIndex("res"));
                String size = cursor.getString(cursor.getColumnIndex("size"));

                ItemWallpaper itemWallpaper = new ItemWallpaper(pid, cid, cname, img, img_thumb, views, totalrate, averagerate, download, tags, type);
                itemWallpaper.setResolution(res);
                itemWallpaper.setSize(size);
                arrayList.add(itemWallpaper);

                cursor.moveToNext();
            }
            cursor.close();
        }

        return arrayList;
    }

    public ArrayList<ItemWallpaper> getWallByCat(String table, String id, String wallType) {
        ArrayList<ItemWallpaper> arrayList = new ArrayList<>();

        if(wallType.equals("")) {
            wallType = "'";
        } else {
            wallType = "' &type='" + wallType+"'";
        }

        Cursor cursor = getData("select * from '" + table + "' where cid = '" + id + wallType);
        if (cursor != null && cursor.getCount() > 0) {
            cursor.moveToFirst();
            for (int i = 0; i < cursor.getCount(); i++) {
                String pid = cursor.getString(cursor.getColumnIndex("pid"));
                String cid = cursor.getString(cursor.getColumnIndex("cid"));
                String cname = cursor.getString(cursor.getColumnIndex("cname"));
                String img = cursor.getString(cursor.getColumnIndex("img"));
                String img_thumb = cursor.getString(cursor.getColumnIndex("img_thumb"));
                String views = cursor.getString(cursor.getColumnIndex("views"));
                String totalrate = cursor.getString(cursor.getColumnIndex("total_rate"));
                String averagerate = cursor.getString(cursor.getColumnIndex("avg_rate"));
                String download = cursor.getString(cursor.getColumnIndex("total_download"));
                String tags = cursor.getString(cursor.getColumnIndex("tags"));
                String type = cursor.getString(cursor.getColumnIndex("type"));
                String res = cursor.getString(cursor.getColumnIndex("res"));
                String size = cursor.getString(cursor.getColumnIndex("size"));

                ItemWallpaper itemWallpaper = new ItemWallpaper(pid, cid, cname, img, img_thumb, views, totalrate, averagerate, download, tags, type);
                itemWallpaper.setResolution(res);
                itemWallpaper.setSize(size);
                arrayList.add(itemWallpaper);

                cursor.moveToNext();
            }
            cursor.close();
        }

        return arrayList;
    }

    public ArrayList<ItemGIF> getGIFs() {
        ArrayList<ItemGIF> arrayList = new ArrayList<>();
        Cursor cursor = getData("select * from gif");
        if (cursor != null && cursor.getCount() > 0) {
            cursor.moveToFirst();
            for (int i = 0; i < cursor.getCount(); i++) {
                String gid = cursor.getString(cursor.getColumnIndex("gid"));
                String img = cursor.getString(cursor.getColumnIndex("image"));
                String views = cursor.getString(cursor.getColumnIndex("views"));
                String total_rate = cursor.getString(cursor.getColumnIndex("total_rate"));
                String avg_rate = cursor.getString(cursor.getColumnIndex("avg_rate"));
                String download = cursor.getString(cursor.getColumnIndex("total_download"));
                String tags = cursor.getString(cursor.getColumnIndex("tags"));
                String res = cursor.getString(cursor.getColumnIndex("res"));
                String size = cursor.getString(cursor.getColumnIndex("size"));

                ItemGIF itemGIF = new ItemGIF(gid, img, views, total_rate, avg_rate, download, tags);
                itemGIF.setResolution(res);
                itemGIF.setSize(size);
                arrayList.add(itemGIF);

                cursor.moveToNext();
            }
            cursor.close();
        }
        return arrayList;
    }

    public ArrayList<ItemCat> getCat() {
        ArrayList<ItemCat> arrayList = new ArrayList<>();

        Cursor cursor = getData("select * from cat");
        if (cursor != null && cursor.getCount() > 0) {
            cursor.moveToFirst();
            for (int i = 0; i < cursor.getCount(); i++) {
                String cid = cursor.getString(cursor.getColumnIndex("cid"));
                String cname = cursor.getString(cursor.getColumnIndex("cname"));
                String img = cursor.getString(cursor.getColumnIndex("img"));
                String tot_wall = cursor.getString(cursor.getColumnIndex("tot_wall"));

                ItemCat itemCategory = new ItemCat(cid, cname, img, "a", tot_wall);
                arrayList.add(itemCategory);

                cursor.moveToNext();
            }
            cursor.close();
        }
        return arrayList;
    }

    public Boolean isFav(String id) {
        String selectQuery = "SELECT  * FROM fav WHERE pid=" + "'" + id + "'";

        Cursor cursor = getData(selectQuery);
        return cursor != null && cursor.getCount() > 0;
    }

    public Boolean isFavGIF(String id) {
        String selectQuery = "SELECT * FROM gif WHERE gid=" + "'" + id + "'";

        Cursor cursor = getData(selectQuery);
        return cursor != null && cursor.getCount() > 0;
    }

    public void addtoFavorite(ItemWallpaper itemWallpaper) {
        dml("insert into fav (pid,cid,cname,img,img_thumb,views, total_rate, avg_rate, total_download, tags, type, res, size) values ('" + itemWallpaper.getId() + "','" + itemWallpaper.getCId() + "','" + itemWallpaper.getCName() + "','" + itemWallpaper.getImage() + "','" + itemWallpaper.getImageThumb() + "','" + itemWallpaper.getTotalViews() + "','" + itemWallpaper.getTotalRate() + "','" + itemWallpaper.getAverageRate() + "','" + itemWallpaper.getTotalDownloads() + "','" + itemWallpaper.getTags() + "','" + itemWallpaper.getType() + "','" + itemWallpaper.getResolution() + "','" + itemWallpaper.getSize() + "')");
    }

    public void removeFav(String id) {
        dml("delete from fav where pid = '" + id + "'");
    }

    public void addWallpaper(ItemWallpaper itemWallpaper, String table) {
        dml("insert into '" + table + "' (pid,cid,cname,img,img_thumb,views, total_rate, avg_rate, total_download, tags, type, res, size) values ('" + itemWallpaper.getId() + "','" + itemWallpaper.getCId() + "','" + itemWallpaper.getCName() + "','" + itemWallpaper.getImage() + "','" + itemWallpaper.getImageThumb() + "','" + itemWallpaper.getTotalViews() + "','" + itemWallpaper.getTotalRate() + "','" + itemWallpaper.getAverageRate() + "','" + itemWallpaper.getTotalDownloads() + "','" + itemWallpaper.getTags() + "','" + itemWallpaper.getType() + "','" + itemWallpaper.getResolution() + "','" + itemWallpaper.getSize() + "')");
    }

    public void removeAllWallpaper(String table) {
        dml("delete from '" + table + "'");
    }

    public void removeWallByCat(String table, String id) {
        dml("delete from '" + table + "' where cid= '" + id + "'");
    }

    public void addtoFavoriteGIF(ItemGIF itemGIF) {
        dml("insert into gif (gid,image,views, total_rate, avg_rate, total_download, tags, res, size) values ('" + itemGIF.getId() + "','" + itemGIF.getImage() + "','" + itemGIF.getTotalViews() + "','" + itemGIF.getTotalRate() + "','" + itemGIF.getAveargeRate() + "','" + itemGIF.getTotalDownload() + "','" + itemGIF.getTags() + "','" + itemGIF.getResolution() + "','" + itemGIF.getSize() + "')");
    }

    public void removeFavGIF(String id) {
        dml("delete from gif where gid = '" + id + "'");
    }

    public void addtoCatList(ItemCat itemCategory) {
        dml("insert into cat (cid,cname,img,tot_wall) values ('" + itemCategory.getId() + "','" + itemCategory.getName() + "','" + itemCategory.getImage() + "','" + itemCategory.getTotalWallpaper() + "')");
    }

    public void removeAllCat() {
        dml("delete from cat");
    }

    public void updateView(String id, String totview, String download, String reso, String size) {
        dml("update catlist set views = '" + totview + "', total_download = '" + download + "', res = '" + reso + "', size = '" + size + "'  where pid = '" + id + "'");
        dml("update fav set views = '" + totview + "', total_download = '" + download + "', res = '" + reso + "', size = '" + size + "' where pid = '" + id + "'");
        dml("update latest set views = '" + totview + "', total_download = '" + download + "', res = '" + reso + "', size = '" + size + "' where pid = '" + id + "'");
    }

    public void updateViewGIF(String id, String totview, String download, String reso, String size) {
        int views = Integer.parseInt(totview) + 1;
        dml("update gif set views = '" + String.valueOf(views) + "', total_download = '" + download + "', res = '" + reso + "', size = '" + size + "' where gid = '" + id + "'");
    }

    public void addtoAbout() {
        try {
            dml("delete from about");
            dml("insert into about (name,logo,version,author,contact,email,website,desc,developed,privacy, ad_pub, ad_banner, ad_inter, isbanner, isinter, click) values (" +
                    "'" + Constant.itemAbout.getAppName() + "','" + Constant.itemAbout.getAppLogo() + "','" + Constant.itemAbout.getAppVersion() + "'" +
                    ",'" + Constant.itemAbout.getAuthor() + "','" + Constant.itemAbout.getContact() + "','" + Constant.itemAbout.getEmail() + "'" +
                    ",'" + Constant.itemAbout.getWebsite() + "','" + Constant.itemAbout.getAppDesc() + "','" + Constant.itemAbout.getDevelopedby() + "'" +
                    ",'" + Constant.itemAbout.getPrivacy() + "','" + Constant.ad_publisher_id + "','" + Constant.ad_banner_id + "','" + Constant.ad_inter_id + "'" +
                    ",'" + Constant.isBannerAd + "','" + Constant.isInterAd + "','" + Constant.adShow + "')");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public Boolean getAbout() {
        String selectQuery = "SELECT * FROM about";

        Cursor c = getData(selectQuery);

        if (c != null && c.getCount() > 0) {
            c.moveToFirst();
            for (int i = 0; i < c.getCount(); i++) {
                String appname = c.getString(c.getColumnIndex("name"));
                String applogo = c.getString(c.getColumnIndex("logo"));
                String desc = c.getString(c.getColumnIndex("desc"));
                String appversion = c.getString(c.getColumnIndex("version"));
                String appauthor = c.getString(c.getColumnIndex("author"));
                String appcontact = c.getString(c.getColumnIndex("contact"));
                String email = c.getString(c.getColumnIndex("email"));
                String website = c.getString(c.getColumnIndex("website"));
                String privacy = c.getString(c.getColumnIndex("privacy"));
                String developedby = c.getString(c.getColumnIndex("developed"));

                Constant.ad_banner_id = c.getString(c.getColumnIndex("ad_banner"));
                Constant.ad_inter_id = c.getString(c.getColumnIndex("ad_inter"));
                Constant.isBannerAd = Boolean.parseBoolean(c.getString(c.getColumnIndex("isbanner")));
                Constant.isInterAd = Boolean.parseBoolean(c.getString(c.getColumnIndex("isinter")));
                Constant.ad_publisher_id = c.getString(c.getColumnIndex("ad_pub"));
                Constant.adShow = Integer.parseInt(c.getString(c.getColumnIndex("click")));

                Constant.itemAbout = new ItemAbout(appname, applogo, desc, appversion, appauthor, appcontact, email, website, privacy, developedby);
            }
            c.close();
            return true;
        } else {
            return false;
        }
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.e("aaa", "upgrade");
        Log.e("aaa -oldVersion", "" + oldVersion);
        Log.e("aaa -newVersion", "" + newVersion);
        try {

            @SuppressLint("SdCardPath") String myPath = "/data/data/" + context.getPackageName() + "/" + "databases/" + DB_NAME;
            db = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
            switch (oldVersion) {
                case 1:
                case 2:
                    db.execSQL("ALTER TABLE gif ADD 'total_rate' TEXT");
                    db.execSQL("ALTER TABLE gif ADD 'avg_rate' TEXT");
                    db.execSQL("ALTER TABLE gif ADD 'total_download' TEXT");
                    db.execSQL("ALTER TABLE gif ADD 'tags' TEXT");

                    db.execSQL("ALTER TABLE latest ADD 'total_rate' TEXT");
                    db.execSQL("ALTER TABLE latest ADD 'avg_rate' TEXT");
                    db.execSQL("ALTER TABLE latest ADD 'total_download' TEXT");
                    db.execSQL("ALTER TABLE latest ADD 'tags' TEXT");

                    db.execSQL("ALTER TABLE fav ADD 'total_rate' TEXT");
                    db.execSQL("ALTER TABLE fav ADD 'avg_rate' TEXT");
                    db.execSQL("ALTER TABLE fav ADD 'total_download' TEXT");
                    db.execSQL("ALTER TABLE fav ADD 'tags' TEXT");

                    db.execSQL("ALTER TABLE catlist ADD 'total_rate' TEXT");
                    db.execSQL("ALTER TABLE catlist ADD 'avg_rate' TEXT");
                    db.execSQL("ALTER TABLE catlist ADD 'total_download' TEXT");
                    db.execSQL("ALTER TABLE catlist ADD 'tags' TEXT");

                    db.execSQL("ALTER TABLE about ADD 'ad_pub' TEXT");
                    db.execSQL("ALTER TABLE about ADD 'ad_banner' TEXT");
                    db.execSQL("ALTER TABLE about ADD 'ad_inter' TEXT");
                    db.execSQL("ALTER TABLE about ADD 'isbanner' TEXT");
                    db.execSQL("ALTER TABLE about ADD 'isinter' TEXT");
                    db.execSQL("ALTER TABLE about ADD 'click' TEXT");
                case 3:

                    db.execSQL("ALTER TABLE latest ADD 'type' TEXT");
                    db.execSQL("ALTER TABLE latest ADD 'res' TEXT");
                    db.execSQL("ALTER TABLE latest ADD 'size' TEXT");

                    db.execSQL("ALTER TABLE fav ADD 'type' TEXT");
                    db.execSQL("ALTER TABLE fav ADD 'res' TEXT");
                    db.execSQL("ALTER TABLE fav ADD 'size' TEXT");

                    db.execSQL("ALTER TABLE catlist ADD 'type' TEXT");
                    db.execSQL("ALTER TABLE catlist ADD 'res' TEXT");
                    db.execSQL("ALTER TABLE catlist ADD 'size' TEXT");

                    db.execSQL("ALTER TABLE gif ADD 'res' TEXT");
                    db.execSQL("ALTER TABLE gif ADD 'size' TEXT");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

https://www.b4x.com/android/forum/threads/class-flexible-table.30649/
https://www.b4x.com/android/forum/threads/universalimageloader-v1-0-2.53217/
https://www.b4x.com/android/forum/threads/cards-list-with-customlistview.87720/#content
https://www.b4x.com/android/forum/threads/b4x-xui-create-a-round-image.85102/#content
 
Last edited:

Schakalaka

Active Member
Licensed User
Longtime User
Sto provando a creare un' activity che mi scarichi questi dati, ma le card che genera, sono una per gni elemento, quando dovrebbero essere una per categoria.
Appena possibile allego il progetto che ho fatto:

B4X:
{
   "HD_WALLPAPER": [
       {
           "cid": "1",
           "category_name": "Abstract",
           "category_image": "http://eliteandroidapp.netsons.org/php_web_services/images/66832_Abstract_Category_400_200.jpg",
           "category_image_thumb": "http://eliteandroidapp.netsons.org/php_web_services/thumb.php?src=images/66832_Abstract_Category_400_200.jpg&size=300x300",
           "category_total_wall": "1"
       },
       {
           "cid": "2",
           "category_name": "Baby",
           "category_image": "http://eliteandroidapp.netsons.org/php_web_services/images/8312_beby_category_1_400_200.jpg",
           "category_image_thumb": "http://eliteandroidapp.netsons.org/php_web_services/thumb.php?src=images/8312_beby_category_1_400_200.jpg&size=300x300",
           "category_total_wall": "1"
       },
       {
           "cid": "3",
           "category_name": "Bike",
           "category_image": "http://eliteandroidapp.netsons.org/php_web_services/images/49067_Bike_Category_400_200.jpg",
           "category_image_thumb": "http://eliteandroidapp.netsons.org/php_web_services/thumb.php?src=images/49067_Bike_Category_400_200.jpg&size=300x300",
           "category_total_wall": "2"
       },
       {
           "cid": "4",
           "category_name": "Bird",
           "category_image": "http://eliteandroidapp.netsons.org/php_web_services/images/38144_Bird.jpg",
           "category_image_thumb": "http://eliteandroidapp.netsons.org/php_web_services/thumb.php?src=images/38144_Bird.jpg&size=300x300",
           "category_total_wall": "1"
       },
       {
           "cid": "5",
           "category_name": "Car",
           "category_image": "http://eliteandroidapp.netsons.org/php_web_services/images/177_Car_Category_400_200.jpg",
           "category_image_thumb": "http://eliteandroidapp.netsons.org/php_web_services/thumb.php?src=images/177_Car_Category_400_200.jpg&size=300x300",
           "category_total_wall": "0"
       },
       {
           "cid": "6",
           "category_name": "Celebrities",
           "category_image": "http://eliteandroidapp.netsons.org/php_web_services/images/66450_fashion_1.jpg",
           "category_image_thumb": "http://eliteandroidapp.netsons.org/php_web_services/thumb.php?src=images/66450_fashion_1.jpg&size=300x300",
           "category_total_wall": "2"
       },
       {
           "cid": "7",
           "category_name": "Love",
           "category_image": "http://eliteandroidapp.netsons.org/php_web_services/images/93863_Love_Category1_400_200.jpg",
           "category_image_thumb": "http://eliteandroidapp.netsons.org/php_web_services/thumb.php?src=images/93863_Love_Category1_400_200.jpg&size=300x300",
           "category_total_wall": "1"
       },
       {
           "cid": "8",
           "category_name": "Nature",
           "category_image": "http://eliteandroidapp.netsons.org/php_web_services/images/99528_nature.jpg",
           "category_image_thumb": "http://eliteandroidapp.netsons.org/php_web_services/thumb.php?src=images/99528_nature.jpg&size=300x300",
           "category_total_wall": "16"
       }
   ]
}
Aiutino grazie
 

Schakalaka

Active Member
Licensed User
Longtime User
son riuscito a fare questo:
Carico i dati in una Cardlist.
Ora vorrei modificare il design..
 

Attachments

  • WallpapersHD b4a 1.0.zip
    509.2 KB · Views: 319

Schakalaka

Active Member
Licensed User
Longtime User
Ciao,
ho analizzato meglio il codice android.
Utilizza anche delle classi.. le ho trasportate sul progetto b4a.

Ora se volessi creare un 'array con le variabili che inizializza la classe posso scrivere così?

Dim AItemWallpaper() As ItemWallpaper = Array(AItemWallpaper)

dove ItemWallpaper è il nome della classse con questo codice all' interno:

B4X:
Public Sub Initialize (Aid As String,ACId As String,ACName As String, Aimage As String,AimageThumb As String, AtotalViews As String, AtotalRate As String, AaverageRate As String, AtotalDownloads As String, Atags As String, ATypes As String)
       
        id = Aid
        CId = ACId
        image  =Aimage
        imageThumb = AimageThumb
        totalViews = AtotalViews
        totalRate = AtotalRate
        averageRate = AaverageRate
        totalDownloads = AtotalDownloads
        tags = Atags
        Types = ATypes
   
End Sub
public Sub getId As String
    Return id
End Sub

...etc....

Ci sono poi queste definizioni che non so come tradurre su b4a:
B4X:
public static Uri uri_setwall;
public static File file;
 
Top